|
string path = "c://date//xyu.txt";
StreamReader sr = new StreamReader(path);
string strLine = sr.ReadLine();
int rowNum = 1;
object missing = System.Reflection.Missing.Value;
ApplicationClass app = new ApplicationClass();
app.Application.Workbooks.Add(true);
Workbook book = (Workbook)app.ActiveWorkbook;
Worksheet sheet = (Worksheet)book.ActiveSheet;
Range r = sheet.get_Range("A1", "C1");
//擷取行數
object[,] objectData = new object[65535, 3];
while (!string.IsNullOrEmpty(strLine))
{
string[] tempArr;
tempArr = strLine.Split(',');
for (int k = 1; k <= tempArr.Length; k++)
{
objectData[rowNum-1, k-1] = tempArr[k - 1];
}
strLine = sr.ReadLine();
rowNum++;
}
r = r.get_Resize(65535, 3);
r.Value2 = objectData;
r.EntireColumn.AutoFit();
//儲存excel檔案
book.SaveCopyAs("D://source.xls");
//關閉檔案
book.Close(false, missing, missing);
//退出excel
app.Quit();
MessageBox.Show("轉化成功!");
|