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