【发布时间】:2011-08-25 16:25:48
【问题描述】:
我有一个 Windows 应用程序,其中使用 webbrowser 控件显示 html 报告。浏览器控件的内容是动态生成的,提供如下
webbrowser1.DocumentText=htmlString;
现在我想在单击“导出到 Excel 按钮”时将 webbrowser 控件内容导出到 excel。
【问题讨论】:
标签: c# html webbrowser-control export-to-excel
我有一个 Windows 应用程序,其中使用 webbrowser 控件显示 html 报告。浏览器控件的内容是动态生成的,提供如下
webbrowser1.DocumentText=htmlString;
现在我想在单击“导出到 Excel 按钮”时将 webbrowser 控件内容导出到 excel。
【问题讨论】:
标签: c# html webbrowser-control export-to-excel
您可以做的第一件事是创建一个 Excel 模板。您可以打开此模板进行编辑并将其保存到其他位置。这个示例 sn-p 可以帮助您。
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。
【讨论】: