DataGrid匯出EXCEL分組Sheet

  • 2465
  • 0

摘要:DataGrid匯出EXCEL分組Sheet

之前小弟有DataGrid.A資料超過65536筆,導致匯出至EXCEL發生錯誤

因此才有這篇匯出EXCEL就會自動分組並開啟sheet

Microsoft.Office.Interop.Excel.Application objExcel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel._Workbook objWorkBook = objExcel.Workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
Microsoft.Office.Interop.Excel._Worksheet objSheet = (Microsoft.Office.Interop.Excel._Worksheet)objWorkBook.Worksheets["Sheet1"];
objSheet.get_Range("A1", Missing.Value).Value2 = "Sheet1Data"
objWorkBook.Sheets.Add(Missing.Value, objSheet, Missing.Value, Missing.Value);
objSheet = (Microsoft.Office.Interop.Excel._Worksheet)objWorkBook.Worksheets["Sheet2"];
objSheet.get_Range("A1", Missing.Value).Value2 = "Sheet2Data"; 

 






Y2J's Life:http://kimenyeh.blogspot.tw/