62,254
社区成员
发帖
与我相关
我的任务
分享
//Microsoft.Office.Interop.Excel.Application xlsApp = new Microsoft.Office.Interop.Excel.Application();
//Workbooks workBooks = xlsApp.Workbooks;
//Workbook workBook = workBooks.Add(XlWBATemplate.xlWBATWorksheet);
//Worksheet workSheet = (Worksheet)workBook.Worksheets[1];
//Range range = null;
//long tbRoC = dt.Tables[0].Rows.Count;
//int tbCoC = dt.Tables[0].Columns.Count;
//long rowRead = 0;
//float percent = 0f;
//for (int i = 0; i < tbCoC; i++)
//{
// workSheet.Cells[1, i + 1] = dt.Tables[0].Columns[i].ColumnName;
// range = (Range)workSheet.Cells[1, i + 1];
//}
//for (int r = 0; r < tbRoC; r++)
//{
// for (int i = 0; i < tbCoC; i++)
// {
// workSheet.Cells[r + 2, i + 1] = dt.Tables[0].Rows[r][i];
// range = (Range)workSheet.Cells[r + 2, i + 1];
// range.EntireColumn.AutoFit();
// }
// percent = ((float)((++rowRead) * 100)) / tbRoC;
// System.Windows.Forms.Application.DoEvents();
//}
//try
//{
// workBook.Saved = true;
// string path = fileSavePath;
// workBook.SaveCopyAs(path);
// fileSaveDirectory += lastName + ":\r\n" + path + "\r\n";
//}
//catch (Exception ex)
//{
// MessageBox.Show(ex.ToString(), "Error for Save, maybe, this xls is opend");
//}
//finally
//{
// workBooks.Close();
// if (xlsApp != null)
// {
// xlsApp.Workbooks.Close();
// xlsApp.Quit();
// int gc = GC.GetGeneration(xlsApp);
// System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsApp);
// xlsApp = null;
// GC.Collect(gc);
// }
// GC.Collect();
// Process[] p = Process.GetProcessesByName("EXCEL");
// for (int i = 0; i < p.Length; i++)
// {
// p[i].Kill();
// }
//}