I encountered some Excel generation problems at work.
You have found many methods on the network, each of which has its own advantages and disadvantages.
Finally, I used the Excel Automation Service of OFFICE to generate an Excel file, that is, using the Com object provided by Excel.
The specific code is as follows:
Public static void CreateExcel ()
{
For (int I = 0; I <1; I ++)
{
String staFile = "D: testx ";
System. Reflection. Missing miss = System. Reflection. Missing. Value;
Excel. ApplicationClass m_objExcel = new Excel. ApplicationClass ();
M_objExcel.Visible = false;
Excel. Workbooks m_objBooks = (Excel. Workbooks) m_objExcel.Workbooks;
Excel. Workbook m_objBook = (Excel. Workbook) (m_objBooks.Add (miss ));
Excel. Worksheet m_objSheet = (Excel. Worksheet) m_objBook.ActiveSheet;
// Write data to an Excel file
Excel. Range er = m_objSheet.get_Range (object) "A1", System. Reflection. Missing. Value );
Er. Value2 = "dfadfa ";
M_objBook.SaveAs (staFile + I. toString () + ". xls ", miss, Excel. xlSaveAsAccessMode. xlNoChange, miss, miss );
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.