一个简单实用类
using Aspose Cells;
class AsposeExcel
{
private string outFileName "";
private string fullFilename "";
private Workbook book null;
private Worksheet sheet null;
public AsposeExcel string outfilename 导出构造数
{
outFileName outfilename;
book new Workbook ;
sheet book Worksheets[0];
}
private void AddTitle string title int rowIndex int columnIndex
{
Cell cell1 sheet Cells[rowIndex columnIndex];
cell1 PutValue title ;
}
private void AddHeader DataTable dt int rowIndex int columnIndex
{
Cell cell null;
for int col 0; col < dt Columns Count; col++
{
cell sheet Cells[rowIndex col + columnIndex];
cell PutValue dt Columns[col] ColumnName ;
}
}
private void AddBody DataTable dt int rowIndex int columnIndex
{
for int r 0; r < dt Rows Count; r++
{
for int c 0; c < dt Columns Count; c++
{
sheet Cells[r + rowIndex c + columnIndex] PutValue dt Rows[r][c] ToString ;
}
}
}
导出
public Boolean DatatableToExcel DataTable dt int rowIndex int columnIndex
{
Boolean yn false;
try
{
sheet Name sheetName;
AddHeader dt rowIndex columnIndex ;
AddBody dt rowIndex+1 columnIndex+1 ;
sheet AutoFitColumns ;
sheet AutoFitRows ;
book Save outFileName ;
yn true;
return yn;
}
catch Exception e
{
return yn;
}
}
}">一个简单实用类
using Aspose Cells;
class AsposeExcel
{
private string outFileName "";
private string fullFilename "";
private Workbook book null;
private Worksheet sheet null;
public AsposeExcel string outfilename 导 [更多]
1