求将ListView导出到Excel?
求将ListView导出到Excel?要求速度快一些的。
找到了一些代码,但导出速度太慢了,难以忍受。
public static void ExpToExcel(ListView listviewname)
{
if (listviewname.Items.Count == 0) return;
Excel.Application excel = new Excel.Application();
Excel.Workbooks workbooks = excel.Workbooks;
Excel.Workbook workbook = workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
Excel.Sheets worksheets = workbook.Worksheets;
Excel.Worksheet sheet = (Excel.Worksheet)worksheets.get_Item(1);
excel.Visible = false;
Excel.Range range;
excel.Cells.Select();
excel.Cells.RowHeight = 20;
excel.Cells.Font.Size = 10;
excel.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
int rowPos = 2;
range = excel.get_Range(sheet.Cells[rowPos, 1], sheet.Cells[rowPos, 1]);
range.Select();
excel.ScreenUpdating = false;
for (int i = 1; i <= listviewname.Columns.Count; i++)
{
range = excel.get_Range(sheet.Cells[rowPos, i], sheet.Cells[rowPos, i]);
range.Borders.LineStyle = 1;
range.Font.Name = "宋体 ";
range.Font.Size = 16;