Asp tutorial. net export excel and set the format
Add reference: microsoft excel 11.0 object library;
Add: using microsoft. office. interop. excel;
1. Open an excel file ==============================
Microsoft. office. interop. excel. application excel1 = new microsoft. office. interop. excel. application ();
Workbook workbook1 = excel1.workbooks. open (@ "e: aaa.xls", type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing );
Excel1.visible = true;
2. Create an excel file ==============================
Microsoft. office. interop. excel. application excel1 = new microsoft. office. interop. excel. application ();
Workbook workbook1 = excel1.workbooks. add (xlwbatemplate. xlwbatworksheet or true );
Worksheet1.activate (); // activate the table sheet1
Excel1.visible = true;
3. Create an excel table ============================
Microsoft. office. interop. excel. application excel1 = new microsoft. office. interop. excel. application ();
Workbook workbook1 = excel1.workbooks. add (true );
Worksheet worksheet1 = (worksheet) workbook1.worksheets ["sheet1"];
Worksheet worksheet1 = (worksheet) workbook1.worksheets. add (type. missing, workbook1.worksheets [1], 1, type. missing );
Excel1.visible = true;
4. Rename an excel table
Microsoft. office. interop. excel. application excel1 = new microsoft. office. interop. excel. application ();
Workbook workbook1 = excel1.workbooks. add (true );
Worksheet worksheet1 = (worksheet) workbook1.worksheets ["sheet1" or 1];
Worksheet1.name = "Work Schedule ";
Excel1.visible = true; 1 2