asp.net报表解决方法(第一次使用cnblogs的blog)
2011-12-28 08:36
405 查看
private string subTotal(int row ,int num)
{
string r = (row+1).ToString();
if( num == 0)//
{
return "=C"+r+"+F"+r+"-I"+r;
}
else
return "=E"+r+"+H"+r+"-K"+r;
}
private string sumTotal(string scol,int firstrow,int num){
string r = num.ToString();
string fr = firstrow.ToString();
return "=Sum("+scol+fr+":"+scol+r+")";
}
private void CreateExcelWorkbook(DataRow[] rows)
{
string strCurrentDir = Server.MapPath("..") + "\\TempReports\\";
string licenseFile = MapPath("..") + "\\XML\\Aspose.Excel.lic";
Excel excel = new Excel(licenseFile, this);
;
string designerFile = strCurrentDir+"cangku2.xls";
excel.Open(designerFile);
Worksheet sheet = excel.Worksheets["Sheet1"];
sheet.Name = "wuzi";
Cells cells = sheet.Cells;
int styleIndex;
styleIndex = excel.Styles.Add();
Aspose.Excel.Style stylecell = excel.Styles[styleIndex];
stylecell.Borders[BorderType.LeftBorder].LineStyle=CellBorderType.Thin;
stylecell.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
stylecell.Borders[BorderType.RightBorder].LineStyle=CellBorderType.Thin;
stylecell.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
int iRow =4;
foreach(DataRow row in rows)
{
cells[iRow,0].PutValue(row[0].ToString());
cells[iRow,1].PutValue(row[1].ToString());
cells[iRow,2].PutValue(row[2]);
cells[iRow,3].PutValue( row[3]);
cells[iRow,4].PutValue(row[4]);
cells[iRow,5].PutValue(row[5]);
cells[iRow,6].PutValue(row[3]);
cells[iRow,7].PutValue(row[6]);
cells[iRow,8].PutValue(row[7]);
cells[iRow,9].PutValue(row[3]);
cells[iRow,10].PutValue(row[8]);
cells[iRow,11].Formula=subTotal(iRow,0);
cells[iRow,12].PutValue(row[3]);
cells[iRow,13].Formula=subTotal(iRow,1);
iRow++;
}
string zj="总计";
cells[iRow,3].PutValue(zj);
cells[iRow,6].PutValue(zj);
cells[iRow,9].PutValue(zj);
cells[iRow,12].PutValue(zj);
cells[iRow,4].Formula=sumTotal("E",5,iRow);
cells[iRow,7].Formula=sumTotal("H",5,iRow);
cells[iRow,10].Formula=sumTotal("K",5,iRow);
cells[iRow,13].Formula=sumTotal("N",5,iRow);
cells[1,8].PutValue(cpStartDate.SelectedDate.ToShortDateString());
cells[1,12].PutValue(cpEndDate.SelectedDate.ToShortDateString());
Range range = cells.CreateRange(4,0,iRow-4+1,14);
range.Style = stylecell;
for(int i = 0; i < excel.Worksheets.Count ; i ++)
{
sheet = excel.Worksheets[i];
if(sheet.Name != "wuzi")
{
excel.Worksheets.RemoveAt(i);
i --;
}
}
/**//*Response.Clear();
Response.Buffer= true;
Response.Charset="GB2312";
this.Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");*/
excel.Save(HttpUtility.UrlEncode("物资进出库汇总.xls",Encoding.UTF8), SaveType.OpenInBrowser,FileFormatType.Default,this.Response);
{
string r = (row+1).ToString();
if( num == 0)//
{
return "=C"+r+"+F"+r+"-I"+r;
}
else
return "=E"+r+"+H"+r+"-K"+r;
}
private string sumTotal(string scol,int firstrow,int num){
string r = num.ToString();
string fr = firstrow.ToString();
return "=Sum("+scol+fr+":"+scol+r+")";
}
private void CreateExcelWorkbook(DataRow[] rows)
{
string strCurrentDir = Server.MapPath("..") + "\\TempReports\\";
string licenseFile = MapPath("..") + "\\XML\\Aspose.Excel.lic";
Excel excel = new Excel(licenseFile, this);
;
string designerFile = strCurrentDir+"cangku2.xls";
excel.Open(designerFile);
Worksheet sheet = excel.Worksheets["Sheet1"];
sheet.Name = "wuzi";
Cells cells = sheet.Cells;
int styleIndex;
styleIndex = excel.Styles.Add();
Aspose.Excel.Style stylecell = excel.Styles[styleIndex];
stylecell.Borders[BorderType.LeftBorder].LineStyle=CellBorderType.Thin;
stylecell.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
stylecell.Borders[BorderType.RightBorder].LineStyle=CellBorderType.Thin;
stylecell.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
int iRow =4;
foreach(DataRow row in rows)
{
cells[iRow,0].PutValue(row[0].ToString());
cells[iRow,1].PutValue(row[1].ToString());
cells[iRow,2].PutValue(row[2]);
cells[iRow,3].PutValue( row[3]);
cells[iRow,4].PutValue(row[4]);
cells[iRow,5].PutValue(row[5]);
cells[iRow,6].PutValue(row[3]);
cells[iRow,7].PutValue(row[6]);
cells[iRow,8].PutValue(row[7]);
cells[iRow,9].PutValue(row[3]);
cells[iRow,10].PutValue(row[8]);
cells[iRow,11].Formula=subTotal(iRow,0);
cells[iRow,12].PutValue(row[3]);
cells[iRow,13].Formula=subTotal(iRow,1);
iRow++;
}
string zj="总计";
cells[iRow,3].PutValue(zj);
cells[iRow,6].PutValue(zj);
cells[iRow,9].PutValue(zj);
cells[iRow,12].PutValue(zj);
cells[iRow,4].Formula=sumTotal("E",5,iRow);
cells[iRow,7].Formula=sumTotal("H",5,iRow);
cells[iRow,10].Formula=sumTotal("K",5,iRow);
cells[iRow,13].Formula=sumTotal("N",5,iRow);
cells[1,8].PutValue(cpStartDate.SelectedDate.ToShortDateString());
cells[1,12].PutValue(cpEndDate.SelectedDate.ToShortDateString());
Range range = cells.CreateRange(4,0,iRow-4+1,14);
range.Style = stylecell;
for(int i = 0; i < excel.Worksheets.Count ; i ++)
{
sheet = excel.Worksheets[i];
if(sheet.Name != "wuzi")
{
excel.Worksheets.RemoveAt(i);
i --;
}
}
/**//*Response.Clear();
Response.Buffer= true;
Response.Charset="GB2312";
this.Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");*/
excel.Save(HttpUtility.UrlEncode("物资进出库汇总.xls",Encoding.UTF8), SaveType.OpenInBrowser,FileFormatType.Default,this.Response);
相关文章推荐
- asp.net报表解决方法(第一次使用cnblogs的blog)
- Asp.Net MVC使用ViewData导致双引号被转义的解决方法
- ASP.NET在IIS上部署使用Oracle数据库无法连接数据库解决方法
- 使用JavaScript脚本无法直接改变Asp.net中Checkbox控件的Enable属性的解决方法
- ASP.NET 使用alert弹出对话框后,CSS样式失效,字体变大的解决方法
- asp.net 用户控件中 使用相对路径的解决方法-------- 图片路径问题(用户控件、图片路径) ,ResolveUrl
- ASP.NET 使用alert弹出对话框后,CSS样式失效,字体变大的解决方法
- 编写asp.net登录界面时,在不会使用cookie的情况下,暂时解决方法.
- ASP.NET使用ALERT后,影响CSS的解决方法
- ASP.NET在IIS上部署使用Oracle数据库无法连接数据库解决方法
- asp.net MVC中使用Html.Checkbox提示该字符串未被识别为有效的布尔值错误的解决方法
- ASP.NET中使用FCKeditor 2.6.3碰到些常见问题的解决方法
- ASP.NET一般处理程序新建一个方法里使用context.Response.Write的解决方法
- VS .NET 2005中水晶报表的使用 http://www.tianyablog.com/blogger/post_show.asp?BlogID=116800&PostID=9731765
- 在ASP.Net 中使用实现windows登陆的方法. (轉自tainkai的專欄.http://blog.csdn.net/tainkai)
- ASP.NET 使用ajaxupload.js插件出现上传较大文件失败的解决方法
- 使用Ajax更新ASP.Net MVC项目中的报表对象方法
- ASP.NET AjaxPro的应用 .AjaxPro使用中“XXX未定义”的一种解决方法(转载的)
- ASP.NET中使用后端代码注册脚本 生成JQUERY-EASYUI的界面错位的解决方法
- ASP.NET使用GridView时,出现错误“必须声明标量变量‘@ID’”的解决方法