使用c#写入在不同函数中创建的工作簿

时间:2016-02-29 15:08:14

标签: c# excel

我的代码目前创建了几个不同的excel文件,但现在我需要将其修改为一个工作簿中的所有内容。我有一个创建工作簿的函数。

create_FileOne()
string newfileName = "File_" + counter + "myFileOne" + DateTime.Now.ToString("MM-dd-yy") + ".xls";
String newfilePath = System.IO.Path.GetTempPath() + newfileName;
Console.WriteLine(newfilePath);

while (File.Exists(newfilePath))
{
    counter++;
    newfileName = "File_" + counter + " myFileOne" + DateTime.Now.ToString("MM-dd-yy") + ".xls";
    newfilePath = System.IO.Path.GetTempPath() + newfileName;
    Console.WriteLine(newfilePath);
}

//xlAPP.Workbooks.Open(); 

如何调用我之前创建的工作簿?

   A      B     C     D
  111    010  00111 00011

 =CONCATENATE(A1,".",B1,".",C1,".",D1)

1 个答案:

答案 0 :(得分:0)

以下代码打开现有工作簿......

using Microsoft.Office.Interop.Excel;

...

Application xlApp = new Application();
Workbook workbook = xlApp.Workbooks.Open(fileName);