2011-08-18 38 views

回答

0

你可以做的第一件事就是创建一个excel模板。比你可以打开这个模板编辑它并将其保存到不同的位置。此示例代码段可以帮助您。

 using System; 
     using Excel = Microsoft.Office.Interop.Excel; 

     class Program 
     { 
      static void Main(string[] args) 
      { 
       var excelApplication = new Excel.Application { Visible = false, DisplayAlerts = false }; 
       Excel.Workbook excelWorkBook = excelApplication.Workbooks.Open(Filename: @"C:\temp\YourTemplate.xlsx"); 
       Excel.Worksheet targetedExcelSheet = (Excel.Worksheet)excelApplication.ActiveWorkbook.Sheets[1]; 
       Excel.Range ATrialRange = targetedExcelSheet.Range["F4", Type.Missing]; 
       ATrialRange.Value2 = "The values that you have parsed from your html string"; 
       excelWorkBook.SaveAs(Filename: @"C:\temp\YourNewlyGenerated.xlsx"); 
       excelWorkBook.Close(); 
       excelApplication.Quit();  
      } 
     } 

您可以使用html敏捷包来解析您的html。

+0

我没有得到这行代码片段ATrialRange.Value2 =“你从你的html字符串中解析出的值”; – user673453

+0

我的建议是手动解析你的html字符串,从你的html中提取这些值。把它写到你的Excel表格中。我不知道从Web浏览器控件导出Excel表单的其他方式。 – cgon

+0

只需要小心使用iterop的东西 - 确保你自己清理,处理异常,关闭文件等,因为它们都不是垃圾收集。 –