110,539
社区成员
发帖
与我相关
我的任务
分享
if (File.Exists(xlsSaveFileName + ".xlsx"))
{
//MessageBox.Show("文件已存在!");
Microsoft.Office.Interop.Excel.Workbook xlBook = excel.Workbooks.Open(@sPath+"\\"+xlsSaveFileName+".xlsx");
//Microsoft.Office.Interop.Excel.Worksheet xlSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlBook.Worksheets[1];
int rows = data.GetLength(0);//行
int cols = data.GetLength(1);//列
//导入数据
for (int j = 0; j < cols; j++)
{
for (int i = 0; i < rows; i++)
{
excel.Cells[i * 100 + 2+T, j + 2] = data[i, j].ToString().Trim();
}
}
try
{
xlBook.Save();
return true;
}
catch
{
return false;
}
finally
{
excel.Quit();
excel = null;
GC.Collect();
}
}