zoukankan      html  css  js  c++  java
  • Excel In C#

    在项目中需要导入Excel文件,其中需要把Excel格式的数据转换为我们私有格式。

    因此需要测试尽可能多的负数,于是乎写了如下的code进行测试:

    代码
    public void ExcelLoadSave(int targetValue,string fileName)
            {
                Excel._Application app 
    = new Excel.Application();
                app.Visible 
    = false;
                Excel.Workbooks wookbooks 
    = app.Workbooks;
                Excel._Workbook workbook 
    = app.Workbooks.Open(fileName, Excel.XlUpdateLinks.xlUpdateLinksUserSetting, false5""""false, Excel.XlPlatform.xlWindows, ""truefalsetruefalsetrue, Excel.XlCorruptLoad.xlNormalLoad);
                Excel._Workbook wookbook 
    = wookbooks.get_Item(1);
                Excel.Sheets sheets 
    = wookbook.Sheets;
                Excel._Worksheet ExcelSheet 
    = (Excel.Worksheet)sheets.get_Item(1);
                Excel.Range CellRange 
    = (Excel.Range)ExcelSheet.Cells[11];
                CellRange.Value2 
    = targetValue;
                workbook.Save();
                wookbook.Close(
    false, Missing.Value, Missing.Value);
                app.Quit();

                KillExcelProcess();

            }

            
    private void KillExcelProcess()
            {
                Process[] pss 
    = Process.GetProcesses();
                
    for (int i = 0; i < pss.Length; i++)
                {
                    
    if (pss[i].ProcessName == "EXCEL.EXE")
                    {
                        pss[i].Kill();
                    }
                }
            }
  • 相关阅读:
    bzoj 1017 魔兽地图DotR
    poj 1322 chocolate
    bzoj 1045 糖果传递
    poj 3067 japan
    timus 1109 Conference(二分图匹配)
    URAL 1205 By the Underground or by Foot?(SPFA)
    URAL 1242 Werewolf(DFS)
    timus 1033 Labyrinth(BFS)
    URAL 1208 Legendary Teams Contest(DFS)
    URAL 1930 Ivan's Car(BFS)
  • 原文地址:https://www.cnblogs.com/xixifusigao/p/1749120.html
Copyright © 2011-2022 走看看