0
我正在使用NOPI库创建Excel文件下载。我需要很长时间和大文件大小的Excel文件中显示大量数据。在asp.net中下载时调整excel文件的大小?
无论如何,我们可以在下载时减少Excel文件大小吗?现在文件大小是32 MB想要这个大小。
当前代码:
If sqlDs.Tables(0).Rows.Count > 0 Then
Dim dtExcel As DataTable = sqlDs.Tables(0)
For Each column In dtExcel.Columns
row.CreateCell(j).SetCellValue(column.ColumnName)
'sheet1.AutoSizeColumn(j)
sheet1.SetColumnWidth(j, 500)
j = (j + 1)
Next
Dim iRow As Integer = 2
'Double Cell Style
Dim cellDoubleStyle As HSSFCellStyle = hssfworkbook.CreateCellStyle
cellDoubleStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("#,##0.00")
'Integer Cell Style
Dim cellIntStyle As HSSFCellStyle = hssfworkbook.CreateCellStyle
cellIntStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0")
'Date Cell Style
Dim cellDateStyle As HSSFCellStyle = hssfworkbook.CreateCellStyle
cellDateStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat(Format("m/d/yy"))
For Each dr As DataRow In dtExcel.Rows
j = 0
Dim value As Double
Dim colInt As Integer
row = sheet1.CreateRow(iRow)
For Each col As DataColumn In dtExcel.Columns
If Double.TryParse(dr(col).ToString, value) Then
Dim cell As HSSFCell = row.CreateCell(j)
If dr(col).ToString.Contains(".") Then
cell.SetCellValue(value)
cell.CellStyle = cellDoubleStyle
Else
cell.SetCellValue(value)
cell.CellStyle = cellIntStyle
End If '
ElseIf IsDate(dr(col).ToString) Then
Dim cell As HSSFCell = row.CreateCell(j)
Dim dt As New DateTime
DateTime.TryParse(dr(col).ToString, dt)
cell.SetCellValue(dt)
cell.CellStyle = cellDateStyle
ElseIf Integer.TryParse(dr(col).ToString, colInt) Then
Dim cell As HSSFCell = row.CreateCell(j)
cell.SetCellValue(colInt)
Else
row.CreateCell(j).SetCellValue(dr(col).ToString)
'sheet1.AutoSizeColumn(j)
End If
j = j + 1
Next
iRow = iRow + 1
Next
End If
我们在C#或vb.net中是否有很好的开源库来创建.xlsx文件? – James123 2012-03-26 13:57:11
您可以使用EPPlus:http://epplus.codeplex.com/ – Sascha 2012-03-26 16:51:07