Aspose打印Excel方法代码

详细链接:https://shop499704308.taobao.com/?spm=a1z38n.10677092.card.11.594c1debsAGeak

下载bin文件地址:http://download.csdn.net/detail/u012949335/9649878

 

此代码是打印给定的Excel格式,然后填充Excel数据方法。

附:Aspose打印Word地址:http://blog.csdn.net/u012949335/article/details/51943134

 

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;
using Aspose.Cells;
using System.Collections.Generic;

 

private void PrintQdb()
        {
            Aspose.Cells.WorkbookDesigner designer = new Aspose.Cells.WorkbookDesigner();
            string path = Server.MapPath(“../ExcelCells/ksqdb.xlsx”);
            designer.Open(path);
            //根据实际情况来获取数据,此代码是获取数据转换为DataTable
            DataTable dt = SqlData.ExecuteDataset(DbConfig.GetSetting(), CommandType.Text, “sql语句”).Tables[0];
            Workbook workbook = designer.Workbook; //工作簿 
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                for (int k = 0; k < dt.Columns.Count; k++)
                {
                    string column = dt.Columns[k].ColumnName;
                    workbook.Worksheets[0].Replace(“$”+column+”$”,dt.Rows[i][column].ToString());
                }
            }
            //根据实际情况来获取数据,此代码是获取数据转换为DataTable
            DataTable dtzcry = SqlData.ExecuteDataset(DbConfig.GetSetting(), CommandType.Text, “”).Tables[0];
            dtzcry.TableName = “qdbdt”;//datable与excel要对应
            designer.SetDataSource(dtzcry);
            designer.Process();
            string filename = HttpUtility.UrlEncode(“xxx表.xls”, Encoding.UTF8);
            if (System.IO.File.Exists(filename))
            {
                System.IO.File.Delete(filename);
            }
            designer.Save(filename, SaveType.OpenInExcel, FileFormatType.Excel2003, HttpContext.Current.Response);
            Response.End();
        }

 

 

 

《Aspose打印Excel方法代码》

 

 

 

    原文作者:筱筱脱脱
    原文地址: https://blog.csdn.net/u012949335/article/details/52779994
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞