做ASPNET项目都会碰到ASPNET报表问题中国式报表的繁琐让我很是反感可没法子啊客户有需求!自然而然想用DCOM直接操作EXCEL马马虎虎算是成了虽说安全性不好资源浪费严重毕竟在局域网中使用凑合吧
不过总是讨厌在服务端那个没有结束的EXCEL进程……一定要把敌人杀死!google了一把原来当今中外都有这个ASPNET报表问题解决方案也有Windows XP下搞定但我在WINDOWS 下搞了整整一天也没杀死得真想自个杀了后来有人推荐了个控件ASPOSE解决ASPNET报表问题这玩意强服务端都不用装EXCEL效果不错!想偷懒的用这玩意一个字——爽!
private string subTotal(int row int num)
{
string r = (row+)ToString();
if( num == )//
{
return =C+r++F+r+I+r;
}
else
return =E+r++H+r+K+r;
}
private string sumTotal(string scolint firstrowint num){
string r = numToString();
string fr = firstrowToString();
return =Sum(+scol+fr+:+scol+r+);
}
private void CreateExcelWorkbook(DataRow[] rows)
{
string strCurrentDir = ServerMapPath() + \\TempReports\\;
string licenseFile = MapPath() + \\XML\\AsposeExcellic;
Excel excel = new Excel(licenseFile this);
string designerFile = strCurrentDir+cangkuxls;
excelOpen(designerFile);
Worksheet sheet = excelWorksheets[Sheet];
sheetName = wuzi;
Cells cells = sheetCells;
int styleIndex;
styleIndex = excelStylesAdd();
AsposeExcelStyle stylecell = excelStyles[styleIndex];
stylecellBorders[BorderTypeLeftBorder]LineStyle=CellBorderTypeThin;
stylecellBorders[BorderTypeTopBorder]LineStyle = CellBorderTypeThin;
stylecellBorders[BorderTypeRightBorder]LineStyle=CellBorderTypeThin;
stylecellBorders[BorderTypeBottomBorder]LineStyle = CellBorderTypeThin;
int iRow =;
foreach(DataRow row in rows)
{
cells[iRow]PutValue(row[]ToString());
cells[iRow]PutValue(row[]ToString());
cells[iRow]PutValue(row[]);
cells[iRow]PutValue( row[]);
cells[iRow]PutValue(row[]);
cells[iRow]PutValue(row[]);
cells[iRow]PutValue(row[]);
cells[iRow]PutValue(row[]);
cells[iRow]PutValue(row[]);
cells[iRow]PutValue(row[]);
cells[iRow]PutValue(row[]);
cells[iRow]Formula=subTotal(iRow);
cells[iRow]PutValue(row[]);
cells[iRow]Formula=subTotal(iRow);
iRow++;
}
string zj=总计;
cells[iRow]PutValue(zj);
cells[iRow]PutValue(zj);
cells[iRow]PutValue(zj);
cells[iRow]PutValue(zj);
cells[iRow]Formula=sumTotal(EiRow);
cells[iRow]Formula=sumTotal(HiRow);
cells[iRow]Formula=sumTotal(KiRow);
cells[iRow]Formula=sumTotal(NiRow);
cells[]PutValue(cpStartDateSelectedDateToShortDateString());
cells[]PutValue(cpEndDateSelectedDateToShortDateString());
Range range = cellsCreateRange(iRow+);
rangeStyle = stylecell;
for(int i = ; i < excelWorksheetsCount ; i ++)
{
sheet = excelWorksheets[i];
if(sheetName != wuzi)
{
excelWorksheetsRemoveAt(i);
i ;
}
}
/*ResponseClear();
ResponseBuffer= true;
ResponseCharset=GB;
thisResponseContentEncoding=SystemTextEncodingGetEncoding(GB);*/
excelSave(HttpUtilityUrlEncode(物资进出库汇总xlsEncodingUTF) SaveTypeOpenInBrowserFileFormatTypeDefaultthisResponse);
}