Esempio n. 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        WordDocument doc     = new WordDocument();
        DataRegion   dataReg = doc.OpenDataRegion("PO_deptName");

        //为方便用户知道哪些地方可以编辑,所以设置了数据区域的背景色
        dataReg.Shading.BackgroundPatternColor = Color.Pink;
        //dataReg.Editing = true;

        PageOfficeCtrl1.SetWriter(doc); // 不要忘记此句代码

        // 设置数据区域点击时的响应js函数
        PageOfficeCtrl1.JsFunction_OnWordDataRegionClick = "OnWordDataRegionClick()";

        PageOfficeCtrl1.AddCustomToolButton("保存", "Save", 1);
        PageOfficeCtrl1.ServerPage     = Request.ApplicationPath + "/pageoffice/server.aspx"; //此行必须
        PageOfficeCtrl1.OfficeToolbars = false;
        PageOfficeCtrl1.Caption        = "为方便用户知道哪些地方可以编辑,所以设置了数据区域的背景色";
        PageOfficeCtrl1.SaveFilePage   = "SaveFile.aspx";
        PageOfficeCtrl1.WebOpen("doc/test.doc", PageOffice.OpenModeType.docSubmitForm, "张三");
    }
Esempio n. 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        PageOffice.WordWriter.WordDocument doc = new PageOffice.WordWriter.WordDocument();
        //获取Table所在的数据区域对象
        PageOffice.WordWriter.DataRegion dataRegion = doc.OpenDataRegion("PO_regTable");
        //打开table,OpenTable(index)方法中的index代表Word文档中table位置的索引,从1开始
        PageOffice.WordWriter.Table table = dataRegion.OpenTable(1);
        //给table中的单元格赋值, OpenCellRC(行, 列)
        table.OpenCellRC(3, 1).Value = "A公司";
        table.OpenCellRC(3, 2).Value = "开发部";
        table.OpenCellRC(3, 3).Value = "李清";
        //插入一空行,InsertRowAfter方法中的参数表示在哪个单元格下面插入一行
        table.InsertRowAfter(table.OpenCellRC(3, 3));

        table.OpenCellRC(4, 1).Value = "B公司";
        table.OpenCellRC(4, 2).Value = "销售部";
        table.OpenCellRC(4, 3).Value = "张三";
        PageOfficeCtrl1.SetWriter(doc);
        PageOfficeCtrl1.ServerPage = Request.ApplicationPath + "/pageoffice/server.aspx";
        PageOfficeCtrl1.WebOpen("doc/test.doc", PageOffice.OpenModeType.docNormalEdit, "张佚名");
    }
Esempio n. 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Workbook wb    = new Workbook();
        Sheet    sheet = wb.OpenSheet("Sheet1");

        //合并单元格
        sheet.OpenTable("B2:F2").Merge();
        Cell cB2 = sheet.OpenCell("B2");

        cB2.Value = "北京某公司产品销售情况";
        //设置水平对齐方式
        cB2.HorizontalAlignment = XlHAlign.xlHAlignCenter;
        cB2.ForeColor           = Color.Red;
        cB2.Font.Size           = 16;

        sheet.OpenTable("B4:B6").Merge();//合并单元格
        Cell cB4 = sheet.OpenCell("B4");

        cB4.Value = "A产品";
        //设置水平对齐方式
        cB4.HorizontalAlignment = XlHAlign.xlHAlignCenter;
        //设置垂直对齐方式
        cB4.VerticalAlignment = XlVAlign.xlVAlignCenter;

        sheet.OpenTable("B7:B9").Merge();//合并单元格
        Cell cB7 = sheet.OpenCell("B7");

        cB7.Value = "B产品";
        cB7.HorizontalAlignment = XlHAlign.xlHAlignCenter;
        cB7.VerticalAlignment   = XlVAlign.xlVAlignCenter;

        PageOfficeCtrl1.SetWriter(wb);


        //设置服务器页面
        PageOfficeCtrl1.ServerPage = Request.ApplicationPath + "/pageoffice/server.aspx";  //此行必须
        PageOfficeCtrl1.AddCustomToolButton("全屏/还原", "IsFullScreen", 4);
        PageOfficeCtrl1.Caption = "演示:使用程序合并指定的单元格并设置格式和赋值";
        PageOfficeCtrl1.WebOpen("doc/test.xls", PageOffice.OpenModeType.xlsNormalEdit, "张三");
    }
Esempio n. 4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        PageOffice.ExcelWriter.Workbook wk    = new PageOffice.ExcelWriter.Workbook();
        PageOffice.ExcelWriter.Sheet    sheet = wk.OpenSheet("Sheet1");
        PageOffice.ExcelWriter.Table    table = sheet.OpenTableByDefinedName("report", 10, 5, false);
        table.DataFields[0].Value = "轮胎";
        table.DataFields[1].Value = "100";
        table.DataFields[2].Value = "120";
        table.DataFields[3].Value = "500";
        table.DataFields[4].Value = "120%";
        table.NextRow();
        table.Close();
        PageOfficeCtrl1.SetWriter(wk);// 注意不要忘记此代码,如果缺少此句代码,不会赋值成功。

        //设置PageOfficeCtrl控件的服务页面
        PageOfficeCtrl1.ServerPage   = Request.ApplicationPath + "/pageoffice/server.aspx";
        PageOfficeCtrl1.Caption      = "给Excel文档中定义名称的单元格赋值";
        PageOfficeCtrl1.SaveDataPage = "SaveData.aspx";
        PageOfficeCtrl1.AddCustomToolButton("保存", "Save()", 1);

        PageOfficeCtrl1.WebOpen("doc/test.xls", PageOffice.OpenModeType.xlsSubmitForm, "操作人姓名");
    }
Esempio n. 5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        WordDocument doc     = new WordDocument();
        DataRegion   dataReg = doc.OpenDataRegion("PO_table");

        PageOffice.WordWriter.Table table = dataReg.OpenTable(1);
        //合并table中的单元格
        table.OpenCellRC(1, 1).MergeTo(1, 4);
        //给合并后的单元格赋值
        table.OpenCellRC(1, 1).Value = "销售情况表";
        //设置单元格文本样式
        table.OpenCellRC(1, 1).Font.Color = Color.Red;
        table.OpenCellRC(1, 1).Font.Size  = 24;
        table.OpenCellRC(1, 1).Font.Name  = "楷体";
        table.OpenCellRC(1, 1).ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;

        PageOfficeCtrl1.SetWriter(doc);                                                      //不要忘记此句代码

        PageOfficeCtrl1.ServerPage    = Request.ApplicationPath + "/pageoffice/server.aspx"; //此行必须
        PageOfficeCtrl1.CustomToolbar = false;
        PageOfficeCtrl1.WebOpen("doc/test.doc", PageOffice.OpenModeType.docAdmin, "张三");
    }
Esempio n. 6
0
    /// <summary>
    /// 套红
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void BtnTaoHong_Click(object sender, EventArgs e)
    {
        //套红模板时,复制模板文件为“正式发文文件”(zhengshi.doc),填充数据和“正文文件”到“正式发文文件”

        //复制模板,命名为正式发文的文件名:zhengshi.doc
        string fileName = "zhengshi.doc";

        mb = Request.Form["templateName"];
        System.IO.File.Copy(Server.MapPath("doc/" + mb),
                            Server.MapPath("doc/" + fileName), true);

        //给正式发文的文件填充数据
        WordDocument doc    = new WordDocument();
        DataRegion   copies = doc.OpenDataRegion("PO_Copies");

        copies.Value = "6";
        DataRegion docNum = doc.OpenDataRegion("PO_DocNum");

        docNum.Value = "001";
        DataRegion issueDate = doc.OpenDataRegion("PO_IssueDate");

        issueDate.Value = "2013-5-30";
        DataRegion issueDept = doc.OpenDataRegion("PO_IssueDept");

        issueDept.Value = "开发部";
        DataRegion sTextS = doc.OpenDataRegion("PO_STextS");

        sTextS.Value = "[word]doc/test.doc[/word]"; // 把正文文件插入到正式文件中
        DataRegion sTitle = doc.OpenDataRegion("PO_sTitle");

        sTitle.Value = "北京某公司文件";
        DataRegion topicWords = doc.OpenDataRegion("PO_TopicWords");

        topicWords.Value = "Pageoffice、 套红";
        PageOfficeCtrl1.SetWriter(doc);

        //打开word文件
        OpenWord(fileName);
    }
Esempio n. 7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string userName = Request.Form["userName"];
        //***************************卓正PageOffice组件的使用********************************
        Workbook wb    = new Workbook();
        Sheet    sheet = wb.OpenSheet("Sheet1");

        PageOffice.ExcelWriter.Table tableA = sheet.OpenTable("C4:D6");
        PageOffice.ExcelWriter.Table tableB = sheet.OpenTable("C7:D9");

        tableA.SubmitName = "tableA";
        tableB.SubmitName = "tableB";

        //根据登录用户名设置数据区域可编辑性
        //A部门经理登录后
        if (userName.Equals("zhangsan"))
        {
            Literal1.Text   = "A部门经理,所以只能编辑A部门的产品数据";
            tableA.ReadOnly = false;
            tableB.ReadOnly = true;
        }
        //B部门经理登录后
        else
        {
            Literal1.Text   = "B部门经理,所以只能编辑B部门的产品数据";
            tableA.ReadOnly = true;
            tableB.ReadOnly = false;
        }

        PageOfficeCtrl1.SetWriter(wb);


        PageOfficeCtrl1.AddCustomToolButton("保存", "Save", 1);
        PageOfficeCtrl1.ServerPage = Request.ApplicationPath + "/pageoffice/server.aspx"; //此行必须

        PageOfficeCtrl1.SaveDataPage = "SaveData.aspx";                                   //保存数据
        PageOfficeCtrl1.SaveFilePage = "SaveFile.aspx";                                   //如果需要保存文档,添加此句代码
        PageOfficeCtrl1.WebOpen("doc/test.xls", PageOffice.OpenModeType.xlsSubmitForm, userName);
    }
Esempio n. 8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string tempFileName = Request.QueryString["temp"];

        PageOffice.ExcelWriter.Workbook wk    = new PageOffice.ExcelWriter.Workbook();
        PageOffice.ExcelWriter.Sheet    sheet = wk.OpenSheet("Sheet1");
        PageOffice.ExcelWriter.Table    table = sheet.OpenTableByDefinedName("report", 10, 5, false);
        table.DataFields[0].Value = "轮胎";
        table.DataFields[1].Value = "100";
        table.DataFields[2].Value = "120";
        table.DataFields[3].Value = "500";
        table.DataFields[4].Value = "120%";
        table.NextRow();
        table.Close();
        // 注意不要忘记此代码,如果缺少此句代码,不会赋值成功。
        //定义单元格对象,参数“year”就是Excel模板中定义的单元格的名称
        PageOffice.ExcelWriter.Cell cellYear = sheet.OpenCellByDefinedName("year");
        // 给单元格赋值

        cellYear.Value = "2015年";

        PageOffice.ExcelWriter.Cell cellName = sheet.OpenCellByDefinedName("name");
        cellName.Value = "张三";

        PageOfficeCtrl1.SetWriter(wk);

        //隐藏菜单栏
        PageOfficeCtrl1.Menubar = false;

        //poCtrl1.setSaveDataPage("SaveData.aspx");
        //poCtrl1.addCustomToolButton("保存", "Save()", 1);
        //设置PageOfficeCtrl控件的服务页面
        PageOfficeCtrl1.ServerPage   = Request.ApplicationPath + "/pageoffice/server.aspx";
        PageOfficeCtrl1.Caption      = "给Excel文档中定义名称的单元格赋值";
        PageOfficeCtrl1.SaveDataPage = "SaveData.aspx";
        PageOfficeCtrl1.AddCustomToolButton("保存", "Save()", 1);

        PageOfficeCtrl1.WebOpen("doc/" + tempFileName, PageOffice.OpenModeType.xlsSubmitForm, "操作人姓名");
    }
Esempio n. 9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        PageOffice.WordWriter.WordDocument wordDoc = new PageOffice.WordWriter.WordDocument();

        //打开数据区域,OpenDataRegion方法的参数代表Word文档中的书签名称
        PageOffice.WordWriter.DataRegion dataRegion1 = wordDoc.OpenDataRegion("PO_userName");
        //设置DataRegion的可编辑性
        dataRegion1.Editing = true;

        PageOffice.WordWriter.DataRegion dataRegion2 = wordDoc.OpenDataRegion("PO_deptName");
        dataRegion2.Editing = true;

        PageOfficeCtrl1.SetWriter(wordDoc);
        //设置保存数据的页面
        PageOfficeCtrl1.SaveDataPage = "SaveData.aspx";
        //设置保存文件的页面
        PageOfficeCtrl1.SaveFilePage = "SaveFile.aspx";
        PageOfficeCtrl1.ServerPage   = Request.ApplicationPath + "/pageoffice/server.aspx";
        PageOfficeCtrl1.AddCustomToolButton("保存", "Save()", 1);
        //如果需要提交数据,必须将WebOpen的第二个参数OpenModeType设置为docSubmitForm
        PageOfficeCtrl1.WebOpen("doc/test.doc", PageOffice.OpenModeType.docSubmitForm, "文档操作人姓名");
    }
Esempio n. 10
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //设置服务器页面
        PageOfficeCtrl1.ServerPage = Request.ApplicationPath + "/pageoffice/server.aspx";
        PageOffice.WordWriter.WordDocument wordDoc = new PageOffice.WordWriter.WordDocument();

        //打开数据区域,OpenDataRegion方法的参数代表Word文档中的书签名称
        PageOffice.WordWriter.DataRegion dataRegion1 = wordDoc.OpenDataRegion("PO_userName");
        //为DataRegion赋值
        dataRegion1.Value = "张三";
        //设置字体样式
        dataRegion1.Font.Color = Color.Blue;
        dataRegion1.Font.Size  = 24f;
        dataRegion1.Font.Name  = "隶书";
        dataRegion1.Font.Bold  = true;

        PageOffice.WordWriter.DataRegion dataRegion2 = wordDoc.OpenDataRegion("PO_deptName");
        dataRegion2.Value      = "人事部";
        dataRegion2.Font.Color = Color.Red;

        PageOfficeCtrl1.SetWriter(wordDoc);
        PageOfficeCtrl1.WebOpen("doc/test.doc", PageOffice.OpenModeType.docNormalEdit, "文档操作人姓名");
    }
Esempio n. 11
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //定义Workbook对象
        PageOffice.ExcelWriter.Workbook workBook = new PageOffice.ExcelWriter.Workbook();
        //定义Sheet对象,"Sheet1"是打开的Excel表单的名称
        PageOffice.ExcelWriter.Sheet sheet = workBook.OpenSheet("Sheet1");
        //定义Cell对象,给单元格赋值
        PageOffice.ExcelWriter.Cell cellB4 = sheet.OpenCell("B4");
        cellB4.Value = "1月";
        //或者直接给Cell赋值
        sheet.OpenCell("C4").Value = "300";
        sheet.OpenCell("D4").Value = "270";
        sheet.OpenCell("E4").Value = "270";
        sheet.OpenCell("F4").Value = string.Format("{0:P}", 270.0 / 300);

        PageOfficeCtrl1.SetWriter(workBook);// 注意不要忘记此代码,如果缺少此句代码,不会赋值成功。

        //设置PageOfficeCtrl控件的服务页面
        PageOfficeCtrl1.ServerPage = Request.ApplicationPath + "/pageoffice/server.aspx";
        PageOfficeCtrl1.Caption    = "简单的给Excel赋值";

        PageOfficeCtrl1.WebOpen("doc/test.xls", PageOffice.OpenModeType.xlsNormalEdit, "操作人姓名");
    }
Esempio n. 12
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string strID = Request.QueryString["id"].ToString();

        //Create the command and the connection
        string          connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|demo.mdb";
        string          sql        = "select * from excel where ID=" + strID;
        OleDbConnection conn       = new OleDbConnection(connString);
        OleDbCommand    cmd        = new OleDbCommand(sql, conn);

        conn.Open();
        cmd.CommandType = CommandType.Text;
        OleDbDataReader Reader     = cmd.ExecuteReader();
        string          docFile    = "";
        string          docSubject = "";

        if (Reader.Read())
        {
            docFile    = Reader["FileName"].ToString();
            docSubject = Reader["Subject"].ToString();
        }
        Reader.Close();
        conn.Close();

        PageOffice.ExcelWriter.Workbook wb = new PageOffice.ExcelWriter.Workbook();
        wb.DisableSheetDoubleClick = true;
        wb.DisableSheetRightClick  = true;

        PageOfficeCtrl1.ServerPage = "pageoffice/server.aspx";
        PageOfficeCtrl1.AddCustomToolButton("另存为...", "saveAs", 1);
        PageOfficeCtrl1.AddCustomToolButton("打印设置", "setPrint", 0);
        PageOfficeCtrl1.AddCustomToolButton("全屏/还原", "setFullScreen", 4);
        PageOfficeCtrl1.Caption = "Excel文件:" + docSubject;
        PageOfficeCtrl1.SetWriter(wb);
        PageOfficeCtrl1.BorderStyle = PageOffice.BorderStyleType.BorderThin;
        PageOfficeCtrl1.WebOpen(Server.MapPath("doc/") + docFile, PageOffice.OpenModeType.xlsReadOnly, "张佚名");
    }
Esempio n. 13
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //设置PageOfficeCtrl控件的服务页面
        PageOfficeCtrl1.ServerPage = Request.ApplicationPath + "/pageoffice/server.aspx";
        //PageOfficeCtrl1.AddCustomToolButton("保存", "Save()", 1);
        PageOfficeCtrl1.Caption = "简单的给Excel赋值";
        //定义Workbook对象
        PageOffice.ExcelWriter.Workbook workBook = new PageOffice.ExcelWriter.Workbook();
        //定义Sheet对象,"Sheet1"是打开的Excel表单的名称
        PageOffice.ExcelWriter.Sheet sheet = workBook.OpenSheet("Sheet1");
        //定义Cell对象
        PageOffice.ExcelWriter.Cell cellB4 = sheet.OpenCell("B4");
        //给单元格赋值
        cellB4.Value = "1月";
        //设置字体颜色
        cellB4.ForeColor = Color.Red;

        PageOffice.ExcelWriter.Cell cellC4 = sheet.OpenCell("C4");
        cellC4.Value     = "300";
        cellC4.ForeColor = Color.Blue;

        PageOffice.ExcelWriter.Cell cellD4 = sheet.OpenCell("D4");
        cellD4.Value     = "270";
        cellD4.ForeColor = Color.Orange;

        PageOffice.ExcelWriter.Cell cellE4 = sheet.OpenCell("E4");
        cellE4.Value     = "270";
        cellE4.ForeColor = Color.Green;

        PageOffice.ExcelWriter.Cell cellF4 = sheet.OpenCell("F4");
        cellF4.Value     = string.Format("{0:P}", 270.0 / 300);
        cellF4.ForeColor = Color.Gray;

        PageOfficeCtrl1.SetWriter(workBook);
        PageOfficeCtrl1.WebOpen("doc/test.xls", PageOffice.OpenModeType.xlsNormalEdit, "操作人姓名");
    }
Esempio n. 14
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //PageOffice组件的引用
        //首先确保已安装了pageoffice服务器端组件,且在项目中已添加了pageoffice文件夹,
        //在该文件夹中已存在posetup.exe和server.aspx服务器端页面,再在前台页面中引入PageOfficeCtrl控件

        PageOffice.WordWriter.WordDocument worddoc = new PageOffice.WordWriter.WordDocument();
        //先在要插入word文件的位置手动插入书签,书签必须以“PO_”为前缀
        //给DataRegion赋值,值的形式为:"[word]word文件路径[/word]"
        PageOffice.WordWriter.DataRegion data1 = worddoc.OpenDataRegion("PO_p1");
        data1.Value = "[word]doc/1.doc[/word]";
        PageOffice.WordWriter.DataRegion data2 = worddoc.OpenDataRegion("PO_p2");
        data2.Value = "[word]doc/2.doc[/word]";
        PageOffice.WordWriter.DataRegion data3 = worddoc.OpenDataRegion("PO_p3");
        data3.Value = "[word]doc/3.doc[/word]";
        //设置服务器页面
        PageOfficeCtrl1.ServerPage = Request.ApplicationPath + "/pageoffice/server.aspx";
        string fileName = "test.doc";

        PageOfficeCtrl1.SetWriter(worddoc);
        PageOfficeCtrl1.Caption = "演示:后台编程插入word文件到数据区域(专业版、企业版)";
        //打开文件
        PageOfficeCtrl1.WebOpen(Server.MapPath("doc/") + fileName, PageOffice.OpenModeType.docNormalEdit, "张佚名");
    }
Esempio n. 15
0
    protected void Page_Load(object sender, EventArgs e)
    {
        PageOfficeCtrl1.ServerPage = Request.ApplicationPath + "/pageoffice/server.aspx";
        if (Request.QueryString["ID"] != null && Request.QueryString["ID"].Length > 0)
        {
            string id      = Request.QueryString["ID"].Trim();
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|demo_salary.mdb";
            string strSql  = "select * from Salary where id =" + id + " order by ID";

            OleDbConnection conn = new OleDbConnection(strConn);
            OleDbCommand    cmd  = new OleDbCommand(strSql, conn);
            conn.Open();
            cmd.CommandType = CommandType.Text;
            OleDbDataReader reader = cmd.ExecuteReader();

            if (reader.Read())
            {
                decimal  result = 0;
                DateTime date   = DateTime.Now;

                //创建WordDocment对象
                WordDocument doc = new WordDocument();
                //打开数据区域
                DataRegion datareg = doc.OpenDataRegion("PO_table");

                //给数据区域赋值
                doc.OpenDataRegion("PO_ID").Value = id;

                //设置数据区域的可编辑性
                doc.OpenDataRegion("PO_UserName").Editing  = true;
                doc.OpenDataRegion("PO_DeptName").Editing  = true;
                doc.OpenDataRegion("PO_SalTotal").Editing  = true;
                doc.OpenDataRegion("PO_SalDeduct").Editing = true;
                doc.OpenDataRegion("PO_SalCount").Editing  = true;
                doc.OpenDataRegion("PO_DataTime").Editing  = true;

                doc.OpenDataRegion("PO_UserName").Value = reader["UserName"].ToString();
                doc.OpenDataRegion("PO_DeptName").Value = reader["DeptName"].ToString();

                if (reader["SalTotal"] != null && decimal.TryParse(reader["SalTotal"].ToString(), out result))
                {
                    doc.OpenDataRegion("PO_SalTotal").Value = decimal.Parse(reader["SalTotal"].ToString()).ToString("c");
                }
                else
                {
                    doc.OpenDataRegion("PO_SalTotal").Value = "¥0.00";
                }

                if (reader["SalDeduct"] != null && decimal.TryParse(reader["SalDeduct"].ToString(), out result))
                {
                    doc.OpenDataRegion("PO_SalDeduct").Value = int.Parse(reader["SalDeduct"].ToString()).ToString("c");
                }
                else
                {
                    doc.OpenDataRegion("PO_SalDeduct").Value = "¥0.00";
                }

                if (reader["SalCount"] != null && decimal.TryParse(reader["SalCount"].ToString(), out result))
                {
                    doc.OpenDataRegion("PO_SalCount").Value = int.Parse(reader["SalCount"].ToString()).ToString("c");
                }
                else
                {
                    doc.OpenDataRegion("PO_SalCount").Value = "¥0.00";
                }

                if (reader["DataTime"] != null && DateTime.TryParse(reader["DataTime"].ToString(), out date))
                {
                    doc.OpenDataRegion("PO_DataTime").Value = DateTime.Parse(reader["DataTime"].ToString()).ToString("yyyy-MM-dd");
                }
                else
                {
                    doc.OpenDataRegion("PO_DataTime").Value = DateTime.Now.ToString("yyyy-MM-dd");
                }

                PageOfficeCtrl1.AddCustomToolButton("保存", "Save()", 1);
                PageOfficeCtrl1.SaveDataPage = "SaveData.aspx?id=" + id;
                PageOfficeCtrl1.SetWriter(doc);
            }
            else
            {
                Page.RegisterClientScriptBlock("", "<script>alert('未获得该员工的工资信息!');location.href='Default.aspx'</script>");
            }
            reader.Close();
            conn.Close();
        }
        else
        {
            Page.RegisterClientScriptBlock("", "<script>alert('未获得该工资信息的ID!');location.href='Default.aspx'</script>");
        }

        PageOfficeCtrl1.WebOpen("doc/template.doc", PageOffice.OpenModeType.docSubmitForm, "someBody");
    }
Esempio n. 16
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["ids"] == null || Request.QueryString["ids"] == "")
        {
            return;
        }
        string idlist = Request.QueryString["ids"].Trim();

        //从数据库中读取数据
        string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|demo_salary.mdb";
        string strSql  = "select * from Salary where ID in(" + idlist + ") order by ID";

        OleDbConnection  conn = new OleDbConnection(strConn);
        OleDbDataAdapter cmd  = new OleDbDataAdapter(strSql, conn);
        DataSet          ds   = new DataSet();

        conn.Open();
        cmd.Fill(ds, "ds");

        WordDocument doc = new WordDocument();

        if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
        {
            DataTable    dt   = ds.Tables[0];
            DataRegion[] data = new DataRegion[ds.Tables[0].Rows.Count];
            PageOffice.WordWriter.Table[] table = new PageOffice.WordWriter.Table[ds.Tables[0].Rows.Count];

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                data[i]       = doc.CreateDataRegion("reg" + i.ToString(), DataRegionInsertType.Before, "[End]");
                data[i].Value = "[word]doc/template.doc[/word]";

                table[i] = data[i].OpenTable(1);
                table[i].OpenCellRC(2, 1).Value = dt.Rows[i]["ID"].ToString();

                //给单元格赋值
                table[i].OpenCellRC(2, 2).Value = dt.Rows[i]["UserName"].ToString();
                table[i].OpenCellRC(2, 3).Value = dt.Rows[i]["DeptName"].ToString();
                decimal  result = 0;
                DateTime date   = DateTime.Now;
                if (dt.Rows[i]["SalTotal"] != null && decimal.TryParse(dt.Rows[i]["SalTotal"].ToString(), out result))
                {
                    table[i].OpenCellRC(2, 4).Value = decimal.Parse(dt.Rows[i]["SalTotal"].ToString()).ToString("c");
                }
                else
                {
                    table[i].OpenCellRC(2, 4).Value = "¥0.00";
                }

                if (dt.Rows[i]["SalDeduct"] != null && decimal.TryParse(dt.Rows[i]["SalDeduct"].ToString(), out result))
                {
                    table[i].OpenCellRC(2, 5).Value = int.Parse(dt.Rows[i]["SalDeduct"].ToString()).ToString("c");
                }
                else
                {
                    table[i].OpenCellRC(2, 5).Value = "¥0.00";
                }

                if (dt.Rows[i]["SalCount"] != null && decimal.TryParse(dt.Rows[i]["SalCount"].ToString(), out result))
                {
                    table[i].OpenCellRC(2, 6).Value = int.Parse(dt.Rows[i]["SalCount"].ToString()).ToString("c");
                }
                else
                {
                    table[i].OpenCellRC(2, 6).Value = "¥0.00";
                }

                if (dt.Rows[i]["DataTime"] != null && DateTime.TryParse(dt.Rows[i]["DataTime"].ToString(), out date))
                {
                    table[i].OpenCellRC(2, 7).Value = DateTime.Parse(dt.Rows[i]["DataTime"].ToString()).ToString("yyyy-MM-dd");
                }
                else
                {
                    table[i].OpenCellRC(2, 7).Value = "";
                }
            }
        }

        conn.Close();

        // 设置PageOffice组件服务页面
        PageOfficeCtrl1.SetWriter(doc);
        PageOfficeCtrl1.ServerPage = Request.ApplicationPath + "/pageoffice/server.aspx";
        PageOfficeCtrl1.Caption    = "生成工资条";
        PageOfficeCtrl1.WebOpen("doc/test.doc", PageOffice.OpenModeType.docAdmin, "somebody");
    }
Esempio n. 17
0
    protected void Page_Load(object sender, EventArgs e)
    {
        PageOffice.ExcelWriter.Workbook wb = new PageOffice.ExcelWriter.Workbook();
        Sheet sheet = wb.OpenSheet("Sheet1");

        Cell cC3 = sheet.OpenCell("C3");

        //设置单元格背景样式
        cC3.BackColor           = Color.AntiqueWhite;
        cC3.Value               = "一月";
        cC3.ForeColor           = Color.Green;
        cC3.HorizontalAlignment = XlHAlign.xlHAlignCenter;

        Cell cD3 = sheet.OpenCell("D3");

        //设置单元格背景样式
        cD3.BackColor           = Color.AntiqueWhite;
        cD3.Value               = "二月";
        cD3.ForeColor           = Color.Green;
        cD3.HorizontalAlignment = XlHAlign.xlHAlignCenter;

        Cell cE3 = sheet.OpenCell("E3");

        //设置单元格背景样式
        cE3.BackColor           = Color.AntiqueWhite;
        cE3.Value               = "三月";
        cE3.ForeColor           = Color.Green;
        cE3.HorizontalAlignment = XlHAlign.xlHAlignCenter;

        Cell cB4 = sheet.OpenCell("B4");

        //设置单元格背景样式
        cB4.BackColor           = Color.SkyBlue;
        cB4.Value               = "住房";
        cB4.ForeColor           = Color.Wheat;
        cB4.HorizontalAlignment = XlHAlign.xlHAlignCenter;

        Cell cB5 = sheet.OpenCell("B5");

        //设置单元格背景样式
        cB5.BackColor           = Color.Teal;
        cB5.Value               = "三餐";
        cB5.ForeColor           = Color.Wheat;
        cB5.HorizontalAlignment = XlHAlign.xlHAlignCenter;

        Cell cB6 = sheet.OpenCell("B6");

        //设置单元格背景样式
        cB6.BackColor           = Color.MediumPurple;
        cB6.Value               = "车费";
        cB6.ForeColor           = Color.Wheat;
        cB6.HorizontalAlignment = XlHAlign.xlHAlignCenter;

        Cell cB7 = sheet.OpenCell("B7");

        //设置单元格背景样式
        cB7.BackColor           = Color.SteelBlue;
        cB7.Value               = "通讯";
        cB7.ForeColor           = Color.Wheat;
        cB7.HorizontalAlignment = XlHAlign.xlHAlignCenter;

        //绘制表格线
        PageOffice.ExcelWriter.Table titleTable = sheet.OpenTable("B3:E10");
        titleTable.Border.Weight     = PageOffice.ExcelWriter.XlBorderWeight.xlThick;
        titleTable.Border.LineColor  = Color.FromArgb(0, 128, 128);
        titleTable.Border.BorderType = PageOffice.ExcelWriter.XlBorderType.xlAllEdges;

        //合并单元格后赋值
        sheet.OpenTable("B1:E2").Merge();
        sheet.OpenTable("B1:E2").RowHeight = 30;//设置行高
        PageOffice.ExcelWriter.Cell B1 = sheet.OpenCell("B1");
        //设置单元格文本样式
        B1.HorizontalAlignment = PageOffice.ExcelWriter.XlHAlign.xlHAlignCenter;
        B1.VerticalAlignment   = PageOffice.ExcelWriter.XlVAlign.xlVAlignCenter;
        B1.ForeColor           = Color.FromArgb(0, 128, 128);
        B1.Value     = "出差开支预算";
        B1.Font.Bold = true;
        B1.Font.Size = 25;

        PageOfficeCtrl1.SetWriter(wb);                                                    // 不要忘记此句代码

        PageOfficeCtrl1.ServerPage = Request.ApplicationPath + "/pageoffice/server.aspx"; //此行必须
        PageOfficeCtrl1.WebOpen("doc/test.xls", PageOffice.OpenModeType.xlsNormalEdit, "张三");
    }
Esempio n. 18
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserName"] == null || Session["UserName"].ToString().Length <= 0)
        {
            Response.Redirect("Login.aspx");
        }

        if (Request.QueryString["ID"] != null && Request.QueryString["ID"].Trim().Length > 0)
        {
            id = Request.QueryString["ID"];
        }
        else
        {
            Response.Redirect("OrderList.aspx");
        }

        LitDate.Text = DateTime.Now.ToShortDateString() + "    " + "星期" + DateTime.Now.DayOfWeek.ToString(("D"));

        // 数据库连接
        string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|demo_excelorder.mdb";
        string strSql = "select * from OrderMaster where ID = " + id;

        DataSet ds = new DataSet();
        using (OleDbConnection connection = new OleDbConnection(connectionString))
        {
            try
            {
                connection.Open();
                OleDbDataAdapter command = new OleDbDataAdapter(strSql, connection);
                command.Fill(ds, "ds");
            }
            catch (System.Data.OleDb.OleDbException ex)
            {
                throw new Exception(ex.Message);
            }
        }

        // 填充数据
        PageOffice.ExcelWriter.Workbook workBook = new PageOffice.ExcelWriter.Workbook();
        //workBook.DisableSheetDoubleClick = true;
        PageOffice.ExcelWriter.Sheet sheet = workBook.OpenSheet("销售订单");
        if (ds.Tables.Count > 0)
        {
            DataTable dt = ds.Tables[0];
            if (dt.Rows.Count > 0)
            {
                #region 客户信息

                sheet.OpenCell("D5").Value = dt.Rows[0]["CustName"].ToString();
                sheet.OpenCell("D5").SubmitName = "CustName";//单元格提交数据 
                sheet.OpenCell("I5").Value = dt.Rows[0]["OrderNum"].ToString();
                sheet.OpenCell("I5").SubmitName = "OrderNum";//单元格提交数据
                sheet.OpenCell("D6").Value = dt.Rows[0]["CustDistrict"].ToString();
                sheet.OpenCell("D6").SubmitName = "CustDistrict";//单元格提交数据
                sheet.OpenCell("I6").Value = dt.Rows[0]["OrderDate"].ToString();
                sheet.OpenCell("I6").SubmitName = "OrderDate";//单元格提交数据
                sheet.OpenCell("D18").Value = dt.Rows[0]["MakerName"].ToString();
                sheet.OpenCell("D18").SubmitName = "UserName";//单元格提交数据
                sheet.OpenCell("H18").Value = dt.Rows[0]["SalesName"].ToString();
                sheet.OpenCell("H18").SubmitName = "SalesName";//单元格提交数据
                sheet.OpenCell("I16").SubmitName = "Amount";//单元格提交数据
                sheet.OpenCell("I16").ReadOnly = true;//将Excel模版中有公式的单元格设置为只读格式,以免覆盖掉公式
                #endregion

                #region 产品信息
                strSql = "select * from OrderDetail where OrderID =" + dt.Rows[0]["ID"];

                DataSet ds2 = new DataSet();
                using (OleDbConnection connection = new OleDbConnection(connectionString))
                {
                    try
                    {
                        connection.Open();
                        OleDbDataAdapter command = new OleDbDataAdapter(strSql, connection);
                        command.Fill(ds2, "ds2");
                    }
                    catch (System.Data.OleDb.OleDbException ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }

                //定义table对象
                PageOffice.ExcelWriter.Table tableD = sheet.OpenTable("D9:D15");//定义table对象
                tableD.ReadOnly = true;//将table设置成只读

                PageOffice.ExcelWriter.Table table = sheet.OpenTable("C9:H15");
                table.SubmitName = "OrderDetail"; //表提交数据

                if (ds2.Tables.Count > 0)
                {
                    DataTable dt2 = ds2.Tables[0];
                    if (dt2.Rows.Count > 0)
                    {
                        for (int j = 0; j < dt2.Rows.Count; j++)
                        {
                            for (int i = 0; i < table.DataFields.Count; i++)
                            {
                                if (i != 1)//跳过Excel模版中有公式的列,让Excel自动计算该列的值
                                {
                                    table.DataFields[i].Value = dt2.Rows[j][i + 1].ToString();
                                }
                            }
                            table.NextRow();//换行
                        }
                    
                    }
                }
                table.Close();//关闭table
                #endregion
            }
        }
       
        PageOfficeCtrl1.SetWriter(workBook);

    }
Esempio n. 19
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserName"] == null || Session["UserName"].ToString().Length <= 0)
        {
            Response.Redirect("Login.aspx");
        }

        LitDate.Text = DateTime.Now.ToShortDateString() + "    " + "星期" + DateTime.Now.DayOfWeek.ToString(("D"));

        PageOffice.ExcelWriter.Workbook wordBook = new PageOffice.ExcelWriter.Workbook();
        PageOffice.ExcelWriter.Sheet    sheet    = wordBook.OpenSheet("查询表");

        // 数据库连接
        string  connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|demo_excelorder.mdb";
        String  strSql           = "SELECT OrderNum,OrderDate,CustName,SalesName,Amount from OrderMaster order by ID desc ";
        DataSet ds = new DataSet();

        using (OleDbConnection connection = new OleDbConnection(connectionString))
        {
            try
            {
                connection.Open();
                OleDbDataAdapter command = new OleDbDataAdapter(strSql, connection);
                command.Fill(ds, "ds");
                connection.Close();
            }
            catch (System.Data.OleDb.OleDbException ex)
            {
                throw new Exception(ex.Message);
            }
        }

        DataTable dt         = new DataTable();
        decimal   totalMoney = 0;

        if (ds != null)
        {
            dt = ds.Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                sheet.OpenCell("B" + (5 + i)).Value = dt.Rows[i]["OrderNum"].ToString();
                if (dt.Rows[0]["OrderDate"] != null && dt.Rows[i]["OrderDate"].ToString().Length > 0)
                {
                    sheet.OpenCell("C" + (5 + i)).Value = DateTime.Parse(dt.Rows[0]["OrderDate"].ToString()).ToShortDateString();
                }
                sheet.OpenCell("D" + (5 + i)).Value = dt.Rows[i]["CustName"].ToString();
                sheet.OpenCell("E" + (5 + i)).Value = dt.Rows[i]["SalesName"].ToString();
                sheet.OpenCell("F" + (5 + i)).Value = string.Format("{0:C2}", Convert.ToDecimal(dt.Rows[i]["Amount"].ToString()));
                totalMoney += decimal.Parse(dt.Rows[i]["Amount"].ToString());

                if (i % 2 == 0)
                {
                    //设置背景色
                    sheet.OpenTable("B" + (5 + i) + ":F" + (5 + i)).BackColor = Color.FromArgb(253, 233, 217);
                }
            }

            //设置前景色
            sheet.OpenTable("B5:F" + (dt.Rows.Count + 4)).ForeColor = Color.FromArgb(148, 138, 84);

            //水平方向对齐方式
            sheet.OpenTable("B5:F" + (dt.Rows.Count + 4)).HorizontalAlignment = PageOffice.ExcelWriter.XlHAlign.xlHAlignLeft;
            sheet.OpenTable("C5:C" + (dt.Rows.Count + 4)).HorizontalAlignment = PageOffice.ExcelWriter.XlHAlign.xlHAlignCenter;
            sheet.OpenTable("E5:E" + (dt.Rows.Count + 4)).HorizontalAlignment = PageOffice.ExcelWriter.XlHAlign.xlHAlignCenter;
            sheet.OpenTable("F5:F" + (dt.Rows.Count + 4)).HorizontalAlignment = PageOffice.ExcelWriter.XlHAlign.xlHAlignRight;
            //竖直方向对齐方式
            sheet.OpenTable("B5:F" + (dt.Rows.Count + 4)).VerticalAlignment = PageOffice.ExcelWriter.XlVAlign.xlVAlignCenter;
        }

        //合计:

        //合并单元格
        sheet.OpenTable("B" + (dt.Rows.Count + 5) + ":F" + (dt.Rows.Count + 5)).Merge();
        //行高
        sheet.OpenTable("B5:F" + (dt.Rows.Count + 6)).RowHeight = 18;
        sheet.OpenTable("B" + (dt.Rows.Count + 5) + ":F" + (dt.Rows.Count + 6)).HorizontalAlignment = PageOffice.ExcelWriter.XlHAlign.xlHAlignLeft;
        sheet.OpenTable("B" + (dt.Rows.Count + 5) + ":F" + (dt.Rows.Count + 6)).VerticalAlignment   = PageOffice.ExcelWriter.XlVAlign.xlVAlignCenter;

        sheet.OpenCell("B" + (dt.Rows.Count + 6)).Value = "合计";
        sheet.OpenTable("C" + (dt.Rows.Count + 6) + ":E" + (dt.Rows.Count + 6)).Merge();
        sheet.OpenCell("F" + (dt.Rows.Count + 6)).Value = string.Format("{0:C2}", totalMoney);
        sheet.OpenTable("F" + (dt.Rows.Count + 6) + ":F" + (dt.Rows.Count + 6)).HorizontalAlignment = PageOffice.ExcelWriter.XlHAlign.xlHAlignRight;
        sheet.OpenTable("B" + (dt.Rows.Count + 6) + ":F" + (dt.Rows.Count + 6)).VerticalAlignment   = PageOffice.ExcelWriter.XlVAlign.xlVAlignCenter;

        //设置字体:大小、名称
        sheet.OpenTable("B5:F" + (dt.Rows.Count + 6)).Font.Size = 9;
        sheet.OpenTable("B5:F" + (dt.Rows.Count + 6)).Font.Name = "宋体";

        //设置Table的边框样式:样式、宽度、颜色(多种边框样式重叠时,需创建Table对象才可实现样式的叠加覆盖)
        PageOffice.ExcelWriter.Table table = sheet.OpenTable("B" + (dt.Rows.Count + 6) + ":F" + (dt.Rows.Count + 6));
        table.Border.BorderType = PageOffice.ExcelWriter.XlBorderType.xlTopEdge;
        table.Border.Weight     = PageOffice.ExcelWriter.XlBorderWeight.xlThin;
        table.Border.LineColor  = Color.FromArgb(148, 138, 84);

        PageOfficeCtrl1.SetWriter(wordBook);
    }
Esempio n. 20
0
    protected void Page_Load(object sender, EventArgs e)
    {
        docID = Request.QueryString["ID"];

        string          connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|demo.mdb";
        OleDbConnection conn       = new OleDbConnection(connString);

        conn.Open();

        string       sql = "select * from leaveRecord where ID=" + docID;
        OleDbCommand cmd = new OleDbCommand(sql, conn);

        cmd.CommandType = CommandType.Text;
        OleDbDataReader Reader = cmd.ExecuteReader();

        if (Reader.Read())
        {
            docFile       = Reader["FileName"].ToString();
            docName       = Reader["Name"].ToString();
            docDept       = Reader["Dept"].ToString();
            docCause      = Reader["Cause"].ToString();
            docNum        = Reader["Num"].ToString();
            docSubmitTime = DateTime.Parse(Reader["SubmitTime"].ToString());
        }
        Reader.Close();
        conn.Close();

        //-----------  PageOffice 服务器端编程开始  -------------------//



        PageOffice.WordWriter.WordDocument doc    = new PageOffice.WordWriter.WordDocument();
        PageOffice.WordWriter.DataRegion   drName = doc.OpenDataRegion("PO_name");
        drName.Value   = docName;
        drName.Editing = true;
        PageOffice.WordWriter.DataRegion drDept = doc.OpenDataRegion("PO_dept");
        drDept.Value = docDept;
        drDept.Shading.BackgroundPatternColor = Color.Silver;
        //drDept.Editing = true;
        PageOffice.WordWriter.DataRegion drCause = doc.OpenDataRegion("PO_cause");
        drCause.Value   = docCause;
        drCause.Editing = true;
        PageOffice.WordWriter.DataRegion drNum = doc.OpenDataRegion("PO_num");
        drNum.Value   = docNum;
        drNum.Editing = true;
        PageOffice.WordWriter.DataRegion drDate = doc.OpenDataRegion("PO_date");
        drDate.Value = docSubmitTime.ToLongDateString();
        drDate.Shading.BackgroundPatternColor = Color.Pink;
        //drDate.Editing = true;
        PageOffice.WordWriter.DataRegion drTip = doc.OpenDataRegion("PO_tip");
        drTip.Font.Italic = true;
        drTip.Value       = "提示:带背景色的文字是只能通过选择设置,[]中的文字是可以录入编辑的。";

        // 设置PageOffice组件服务页面
        PageOfficeCtrl1.ServerPage = "pageoffice/server.aspx";

        // 设置界面样式
        PageOfficeCtrl1.Caption     = "用户填写请假条";
        PageOfficeCtrl1.BorderStyle = PageOffice.BorderStyleType.BorderThin;
        // 添加自定义工具条按钮
        PageOfficeCtrl1.AddCustomToolButton("保存", "poSave", 1);
        PageOfficeCtrl1.AddCustomToolButton("全屏/还原", "poSetFullScreen", 4);

        PageOfficeCtrl1.JsFunction_OnWordDataRegionClick = "OnWordDataRegionClick()";
        // 设置保存文档的服务器页面
        PageOfficeCtrl1.SaveDataPage = "SaveData.aspx?ID=" + docID;
        ////获取数据对象
        PageOfficeCtrl1.SetWriter(doc);
        // 打开文档
        PageOfficeCtrl1.WebOpen("doc/template.doc", PageOffice.OpenModeType.docSubmitForm, "Tom");
        //-----------  PageOffice 服务器端编程结束  -------------------//
    }
Esempio n. 21
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string fileName = "test.xls";

        PageOffice.ExcelWriter.Workbook wb = new PageOffice.ExcelWriter.Workbook();
        // 设置背景
        PageOffice.ExcelWriter.Table backGroundTable = wb.OpenSheet("Sheet1").OpenTable("A1:P200");
        backGroundTable.Border.LineColor = Color.White;

        // 设置标题
        wb.OpenSheet("Sheet1").OpenTable("A1:H2").Merge();
        wb.OpenSheet("Sheet1").OpenTable("A1:H2").RowHeight = 30;
        PageOffice.ExcelWriter.Cell A1 = wb.OpenSheet("Sheet1").OpenCell("A1");
        A1.HorizontalAlignment = PageOffice.ExcelWriter.XlHAlign.xlHAlignCenter;
        A1.VerticalAlignment   = PageOffice.ExcelWriter.XlVAlign.xlVAlignCenter;
        A1.ForeColor           = Color.FromArgb(0, 128, 128);
        A1.Value     = "出差开支预算";
        A1.Font.Bold = true;
        A1.Font.Size = 25;

        #region 画表头
        // 画表头
        PageOffice.ExcelWriter.Border C4Border = wb.OpenSheet("Sheet1").OpenTable("C4:C4").Border;
        C4Border.Weight    = PageOffice.ExcelWriter.XlBorderWeight.xlThick;
        C4Border.LineColor = Color.Yellow;

        PageOffice.ExcelWriter.Table titleTable = wb.OpenSheet("Sheet1").OpenTable("B4:H5");
        titleTable.Border.Weight     = PageOffice.ExcelWriter.XlBorderWeight.xlThick;
        titleTable.Border.LineColor  = Color.FromArgb(0, 128, 128);
        titleTable.Border.BorderType = PageOffice.ExcelWriter.XlBorderType.xlAllEdges;
        #endregion

        #region 画表体
        // 画表体
        PageOffice.ExcelWriter.Table bodyTable = wb.OpenSheet("Sheet1").OpenTable("B6:H15");
        bodyTable.Border.LineColor = Color.Gray;
        bodyTable.Border.Weight    = PageOffice.ExcelWriter.XlBorderWeight.xlHairline;

        PageOffice.ExcelWriter.Border B7Border = wb.OpenSheet("Sheet1").OpenTable("B7:B7").Border;
        B7Border.LineColor = Color.White;

        PageOffice.ExcelWriter.Border B9Border = wb.OpenSheet("Sheet1").OpenTable("B9:B9").Border;
        B9Border.BorderType = PageOffice.ExcelWriter.XlBorderType.xlBottomEdge;
        B9Border.LineColor  = Color.White;

        PageOffice.ExcelWriter.Border C6C15BorderLeft = wb.OpenSheet("Sheet1").OpenTable("C6:C15").Border;
        C6C15BorderLeft.LineColor  = Color.White;
        C6C15BorderLeft.BorderType = PageOffice.ExcelWriter.XlBorderType.xlLeftEdge;
        PageOffice.ExcelWriter.Border C6C15BorderRight = wb.OpenSheet("Sheet1").OpenTable("C6:C15").Border;
        C6C15BorderRight.LineColor  = Color.Yellow;
        C6C15BorderRight.LineStyle  = PageOffice.ExcelWriter.XlBorderLineStyle.xlDot;
        C6C15BorderRight.BorderType = PageOffice.ExcelWriter.XlBorderType.xlRightEdge;

        PageOffice.ExcelWriter.Border E6E15Border = wb.OpenSheet("Sheet1").OpenTable("E6:E15").Border;
        E6E15Border.LineStyle  = PageOffice.ExcelWriter.XlBorderLineStyle.xlDot;
        E6E15Border.BorderType = PageOffice.ExcelWriter.XlBorderType.xlAllEdges;
        E6E15Border.LineColor  = Color.Yellow;

        PageOffice.ExcelWriter.Border G6G15BorderRight = wb.OpenSheet("Sheet1").OpenTable("G6:G15").Border;
        G6G15BorderRight.BorderType = PageOffice.ExcelWriter.XlBorderType.xlRightEdge;
        G6G15BorderRight.LineColor  = Color.White;
        PageOffice.ExcelWriter.Border G6G15BorderLeft = wb.OpenSheet("Sheet1").OpenTable("G6:G15").Border;
        G6G15BorderLeft.LineStyle  = PageOffice.ExcelWriter.XlBorderLineStyle.xlDot;
        G6G15BorderLeft.BorderType = PageOffice.ExcelWriter.XlBorderType.xlLeftEdge;
        G6G15BorderLeft.LineColor  = Color.Yellow;

        PageOffice.ExcelWriter.Table bodyTable2 = wb.OpenSheet("Sheet1").OpenTable("B6:H15");
        bodyTable2.Border.Weight     = PageOffice.ExcelWriter.XlBorderWeight.xlThick;
        bodyTable2.Border.LineColor  = Color.FromArgb(0, 128, 128);
        bodyTable2.Border.BorderType = PageOffice.ExcelWriter.XlBorderType.xlAllEdges;
        #endregion

        #region 画表尾
        // 画表尾
        PageOffice.ExcelWriter.Border H16H17Border = wb.OpenSheet("Sheet1").OpenTable("H16:H17").Border;
        H16H17Border.LineColor = Color.FromArgb(204, 255, 204);

        PageOffice.ExcelWriter.Border E16G17Border = wb.OpenSheet("Sheet1").OpenTable("E16:G17").Border;
        E16G17Border.LineColor = Color.FromArgb(0, 128, 128);

        PageOffice.ExcelWriter.Table footTable = wb.OpenSheet("Sheet1").OpenTable("B16:H17");
        footTable.Border.Weight     = PageOffice.ExcelWriter.XlBorderWeight.xlThick;
        footTable.Border.LineColor  = Color.FromArgb(0, 128, 128);
        footTable.Border.BorderType = PageOffice.ExcelWriter.XlBorderType.xlAllEdges;
        #endregion

        #region 设置行高列宽
        // 设置行高列宽
        wb.OpenSheet("Sheet1").OpenTable("A1:A1").ColumnWidth = 1;
        wb.OpenSheet("Sheet1").OpenTable("B1:B1").ColumnWidth = 20;
        wb.OpenSheet("Sheet1").OpenTable("C1:C1").ColumnWidth = 15;
        wb.OpenSheet("Sheet1").OpenTable("D1:D1").ColumnWidth = 10;
        wb.OpenSheet("Sheet1").OpenTable("E1:E1").ColumnWidth = 8;
        wb.OpenSheet("Sheet1").OpenTable("F1:F1").ColumnWidth = 3;
        wb.OpenSheet("Sheet1").OpenTable("G1:G1").ColumnWidth = 12;
        wb.OpenSheet("Sheet1").OpenTable("H1:H1").ColumnWidth = 20;

        wb.OpenSheet("Sheet1").OpenTable("A16:A16").RowHeight = 20;
        wb.OpenSheet("Sheet1").OpenTable("A17:A17").RowHeight = 20;
        #endregion

        // 设置表格中字体大小为10
        for (int i = 0; i < 12; i++)
        {
            for (int j = 0; j < 7; j++)
            {
                wb.OpenSheet("Sheet1").OpenCellRC(4 + i, 2 + j).Font.Size = 10;
            }
        }

        #region 填充单元格背景颜色

        // 填充单元格背景颜色
        for (int i = 0; i < 10; i++)
        {
            wb.OpenSheet("Sheet1").OpenCell("H" + (6 + i).ToString()).BackColor = Color.FromArgb(255, 255, 153);
        }

        wb.OpenSheet("Sheet1").OpenCell("E16").BackColor = Color.FromArgb(0, 128, 128);
        wb.OpenSheet("Sheet1").OpenCell("F16").BackColor = Color.FromArgb(0, 128, 128);
        wb.OpenSheet("Sheet1").OpenCell("G16").BackColor = Color.FromArgb(0, 128, 128);
        wb.OpenSheet("Sheet1").OpenCell("E17").BackColor = Color.FromArgb(0, 128, 128);
        wb.OpenSheet("Sheet1").OpenCell("F17").BackColor = Color.FromArgb(0, 128, 128);
        wb.OpenSheet("Sheet1").OpenCell("G17").BackColor = Color.FromArgb(0, 128, 128);

        wb.OpenSheet("Sheet1").OpenCell("H16").BackColor = Color.FromArgb(204, 255, 204);
        wb.OpenSheet("Sheet1").OpenCell("H17").BackColor = Color.FromArgb(204, 255, 204);
        #endregion

        #region 填充单元格文本和公式

        //填充单元格文本和公式
        PageOffice.ExcelWriter.Cell B4 = wb.OpenSheet("Sheet1").OpenCell("B4");
        B4.Font.Bold = true;
        B4.Value     = "出差开支预算";
        PageOffice.ExcelWriter.Cell H5 = wb.OpenSheet("Sheet1").OpenCell("H5");
        H5.Font.Bold           = true;
        H5.Value               = "总计";
        H5.HorizontalAlignment = PageOffice.ExcelWriter.XlHAlign.xlHAlignCenter;
        PageOffice.ExcelWriter.Cell B6 = wb.OpenSheet("Sheet1").OpenCell("B6");
        B6.Font.Bold = true;
        B6.Value     = "飞机票价";
        PageOffice.ExcelWriter.Cell B9 = wb.OpenSheet("Sheet1").OpenCell("B9");
        B9.Font.Bold = true;
        B9.Value     = "酒店";
        PageOffice.ExcelWriter.Cell B11 = wb.OpenSheet("Sheet1").OpenCell("B11");
        B11.Font.Bold = true;
        B11.Value     = "餐饮";
        PageOffice.ExcelWriter.Cell B12 = wb.OpenSheet("Sheet1").OpenCell("B12");
        B12.Font.Bold = true;
        B12.Value     = "交通费用";
        PageOffice.ExcelWriter.Cell B13 = wb.OpenSheet("Sheet1").OpenCell("B13");
        B13.Font.Bold = true;
        B13.Value     = "休闲娱乐";
        PageOffice.ExcelWriter.Cell B14 = wb.OpenSheet("Sheet1").OpenCell("B14");
        B14.Font.Bold = true;
        B14.Value     = "礼品";
        PageOffice.ExcelWriter.Cell B15 = wb.OpenSheet("Sheet1").OpenCell("B15");
        B15.Font.Bold = true;
        B15.Font.Size = 10;
        B15.Value     = "其他费用";

        wb.OpenSheet("Sheet1").OpenCell("C6").Value  = "机票单价(往)";
        wb.OpenSheet("Sheet1").OpenCell("C7").Value  = "机票单价(返)";
        wb.OpenSheet("Sheet1").OpenCell("C8").Value  = "其他";
        wb.OpenSheet("Sheet1").OpenCell("C9").Value  = "每晚费用";
        wb.OpenSheet("Sheet1").OpenCell("C10").Value = "其他";
        wb.OpenSheet("Sheet1").OpenCell("C11").Value = "每天费用";
        wb.OpenSheet("Sheet1").OpenCell("C12").Value = "每天费用";
        wb.OpenSheet("Sheet1").OpenCell("C13").Value = "总计";
        wb.OpenSheet("Sheet1").OpenCell("C14").Value = "总计";
        wb.OpenSheet("Sheet1").OpenCell("C15").Value = "总计";

        wb.OpenSheet("Sheet1").OpenCell("G6").Value  = "  张";
        wb.OpenSheet("Sheet1").OpenCell("G7").Value  = "  张";
        wb.OpenSheet("Sheet1").OpenCell("G9").Value  = "  晚";
        wb.OpenSheet("Sheet1").OpenCell("G10").Value = "  晚";
        wb.OpenSheet("Sheet1").OpenCell("G11").Value = "  天";
        wb.OpenSheet("Sheet1").OpenCell("G12").Value = "  天";

        wb.OpenSheet("Sheet1").OpenCell("H6").Formula  = "=D6*F6";
        wb.OpenSheet("Sheet1").OpenCell("H7").Formula  = "=D7*F7";
        wb.OpenSheet("Sheet1").OpenCell("H8").Formula  = "=D8*F8";
        wb.OpenSheet("Sheet1").OpenCell("H9").Formula  = "=D9*F9";
        wb.OpenSheet("Sheet1").OpenCell("H10").Formula = "=D10*F10";
        wb.OpenSheet("Sheet1").OpenCell("H11").Formula = "=D11*F11";
        wb.OpenSheet("Sheet1").OpenCell("H12").Formula = "=D12*F12";
        wb.OpenSheet("Sheet1").OpenCell("H13").Formula = "=D13*F13";
        wb.OpenSheet("Sheet1").OpenCell("H14").Formula = "=D14*F14";
        wb.OpenSheet("Sheet1").OpenCell("H15").Formula = "=D15*F15";

        for (int i = 0; i < 10; i++)
        {
            wb.OpenSheet("Sheet1").OpenCell("D" + (6 + i).ToString()).NumberFormatLocal = "¥#,##0.00;¥-#,##0.00";
            wb.OpenSheet("Sheet1").OpenCell("H" + (6 + i).ToString()).NumberFormatLocal = "¥#,##0.00;¥-#,##0.00";
        }


        PageOffice.ExcelWriter.Cell E16 = wb.OpenSheet("Sheet1").OpenCell("E16");
        E16.Font.Bold         = true;
        E16.Font.Size         = 11;
        E16.ForeColor         = Color.White;
        E16.Value             = "出差开支总费用";
        E16.VerticalAlignment = PageOffice.ExcelWriter.XlVAlign.xlVAlignCenter;
        PageOffice.ExcelWriter.Cell E17 = wb.OpenSheet("Sheet1").OpenCell("E17");
        E17.Font.Bold         = true;
        E17.Font.Size         = 11;
        E17.ForeColor         = Color.White;
        E17.Formula           = "=IF(C4>H16,\"低于预算\",\"超出预算\")";
        E17.VerticalAlignment = PageOffice.ExcelWriter.XlVAlign.xlVAlignCenter;
        PageOffice.ExcelWriter.Cell H16 = wb.OpenSheet("Sheet1").OpenCell("H16");
        H16.VerticalAlignment = PageOffice.ExcelWriter.XlVAlign.xlVAlignCenter;
        H16.NumberFormatLocal = "¥#,##0.00;¥-#,##0.00";
        H16.Font.Name         = "Arial";
        H16.Font.Size         = 11;
        H16.Font.Bold         = true;
        H16.Formula           = "=SUM(H6:H15)";
        PageOffice.ExcelWriter.Cell H17 = wb.OpenSheet("Sheet1").OpenCell("H17");
        H17.VerticalAlignment = PageOffice.ExcelWriter.XlVAlign.xlVAlignCenter;
        H17.NumberFormatLocal = "¥#,##0.00;¥-#,##0.00";
        H17.Font.Name         = "Arial";
        H17.Font.Size         = 11;
        H17.Font.Bold         = true;
        H17.Formula           = "=(C4-H16)";
        #endregion

        #region 填充数据
        // 填充数据
        PageOffice.ExcelWriter.Cell C4 = wb.OpenSheet("Sheet1").OpenCell("C4");
        C4.NumberFormatLocal = "¥#,##0.00;¥-#,##0.00";
        C4.Value             = "2500";
        PageOffice.ExcelWriter.Cell D6 = wb.OpenSheet("Sheet1").OpenCell("D6");
        D6.NumberFormatLocal = "¥#,##0.00;¥-#,##0.00";
        D6.Value             = "1200";
        wb.OpenSheet("Sheet1").OpenCell("F6").Font.Size = 10;
        wb.OpenSheet("Sheet1").OpenCell("F6").Value     = "1";
        PageOffice.ExcelWriter.Cell D7 = wb.OpenSheet("Sheet1").OpenCell("D7");
        D7.NumberFormatLocal = "¥#,##0.00;¥-#,##0.00";
        D7.Value             = "875";
        wb.OpenSheet("Sheet1").OpenCell("F7").Value = "1";

        #endregion

        PageOfficeCtrl1.BorderStyle = PageOffice.BorderStyleType.BorderThin;
        PageOfficeCtrl1.Caption     = "完全使用程序生成Excel表格";
        // 打开文件
        PageOfficeCtrl1.ServerPage = "pageoffice/server.aspx";
        PageOfficeCtrl1.SetWriter(wb);
        PageOfficeCtrl1.WebOpen(Server.MapPath("doc/") + fileName, PageOffice.OpenModeType.xlsNormalEdit, "张佚名");
    }
Esempio n. 22
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserName"] == null || Session["UserName"].ToString().Length <= 0)
        {
            Response.Redirect("Login.aspx");
        }

        LitDate.Text = DateTime.Now.ToShortDateString() + "    " + "星期" + DateTime.Now.DayOfWeek.ToString(("D"));

        PageOffice.ExcelWriter.Workbook wordBook = new PageOffice.ExcelWriter.Workbook();
        PageOffice.ExcelWriter.Sheet    sheet    = wordBook.OpenSheet("统计图表");

        string        connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|demo_excelorder.mdb";
        StringBuilder strSql           = new StringBuilder();

        strSql.Append("SELECT OrderMaster.SalesName, OrderDetail.ProductName, sum(OrderDetail.Quantity) as Quantity, sum(OrderDetail.Price * OrderDetail.Quantity) as amount ");
        strSql.Append(" from OrderMaster,OrderDetail ");
        strSql.Append(" where OrderMaster.ID = OrderDetail.OrderID and OrderMaster.SalesName in('阿土伯','金贝贝','钱夫人','孙小美') ");
        strSql.Append(" group by OrderMaster.SalesName, OrderDetail.ProductName ");

        DataSet ds = new DataSet();

        using (OleDbConnection connection = new OleDbConnection(connectionString))
        {
            try
            {
                connection.Open();
                OleDbDataAdapter command = new OleDbDataAdapter(strSql.ToString(), connection);
                command.Fill(ds, "ds");
                connection.Close();
            }
            catch (System.Data.OleDb.OleDbException ex)
            {
                throw new Exception(ex.Message);
            }
        }

        DataTable dt = new DataTable();
        int       n  = 0;

        if (ds != null)
        {
            dt = ds.Tables[0];
            int columnId = 5;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (1 == columnId % 4)
                {
                    sheet.OpenCell("B" + columnId).Value = dt.Rows[i]["SalesName"].ToString();
                }

                switch (dt.Rows[i]["ProductName"].ToString())
                {
                case "笔记本":
                {
                    sheet.OpenCell("C" + (columnId).ToString()).Value = dt.Rows[i]["ProductName"].ToString();
                    sheet.OpenCell("D" + (columnId).ToString()).Value = dt.Rows[i]["Quantity"].ToString();
                    sheet.OpenCell("E" + (columnId).ToString()).Value = dt.Rows[i]["amount"].ToString();
                    break;
                }

                case "服务器":
                {
                    sheet.OpenCell("C" + (columnId + 1).ToString()).Value = dt.Rows[i]["ProductName"].ToString();
                    sheet.OpenCell("D" + (columnId + 1).ToString()).Value = dt.Rows[i]["Quantity"].ToString();
                    sheet.OpenCell("E" + (columnId + 1).ToString()).Value = dt.Rows[i]["amount"].ToString();
                    break;
                }

                case "路由器":
                {
                    sheet.OpenCell("C" + (columnId + 2).ToString()).Value = dt.Rows[i]["ProductName"].ToString();
                    sheet.OpenCell("D" + (columnId + 2).ToString()).Value = dt.Rows[i]["Quantity"].ToString();
                    sheet.OpenCell("E" + (columnId + 2).ToString()).Value = dt.Rows[i]["amount"].ToString();
                    break;
                }
                }

                if (i < dt.Rows.Count - 1 &&
                    !dt.Rows[i]["SalesName"].ToString().Equals(dt.Rows[i + 1]["SalesName"].ToString()))
                {
                    n++;
                    columnId = 5 + n * 4;
                }
            }
        }

        PageOfficeCtrl1.SetWriter(wordBook);
    }
Esempio n. 23
0
    protected void Page_Load(object sender, EventArgs e)
    {
        PageOffice.WordWriter.WordDocument doc = new PageOffice.WordWriter.WordDocument();

        //设置内容标题

        //创建DataRegion对象,PO_title为自动添加的书签名称,书签名称需以“PO_”为前缀,切书签名称不能重复
        //三个参数分别为要新插入书签的名称、新书签的插入位置、相关联的书签名称(“[home]”代表Word文档的第一个位置)
        PageOffice.WordWriter.DataRegion title = doc.CreateDataRegion("PO_title",
                                                                      PageOffice.WordWriter.DataRegionInsertType.After, "[home]");
        //给DataRegion对象赋值
        title.Value = "C#中Socket多线程编程实例\n";
        //设置字体:粗细、大小、字体名称、是否是斜体
        title.Font.Bold   = true;
        title.Font.Size   = 20;
        title.Font.Name   = "黑体";
        title.Font.Italic = false;
        //定义段落对象
        PageOffice.WordWriter.ParagraphFormat titlePara = title.ParagraphFormat;
        //设置段落对齐方式
        titlePara.Alignment = PageOffice.WordWriter.WdParagraphAlignment.wdAlignParagraphCenter;
        //设置段落行间距
        titlePara.LineSpacingRule = PageOffice.WordWriter.WdLineSpacing.wdLineSpaceMultiple;

        //设置内容
        //第一段
        //创建DataRegion对象,PO_body为自动添加的书签名称
        PageOffice.WordWriter.DataRegion body = doc.CreateDataRegion("PO_body", PageOffice.WordWriter.DataRegionInsertType.After, "PO_title");
        //设置字体:粗细、是否是斜体、大小、字体名称、字体颜色
        body.Font.Bold   = false;
        body.Font.Italic = true;
        body.Font.Size   = 10;
        //设置中文字体名称
        body.Font.Name = "楷体";
        //设置英文字体名称
        body.Font.NameAscii = "Times New Roman";
        body.Font.Color     = Color.Red;
        //给DataRegion对象赋值
        body.Value = "是微软随着VS.net新推出的一门语言。它作为一门新兴的语言,有着C++的强健,又有着VB等的RAD特性。而且,微软推出C#主要的目的是为了对抗Sun公司的Java。大家都知道Java语言的强大功能,尤其在网络编程方面。于是,C#在网络编程方面也自然不甘落后于人。本文就向大家介绍一下C#下实现套接字(Sockets)编程的一些基本知识,以期能使大家对此有个大致了解。首先,我向大家介绍一下套接字的概念。\n";
        //创建ParagraphFormat对象
        PageOffice.WordWriter.ParagraphFormat bodyPara = body.ParagraphFormat;
        //设置段落的行间距、对齐方式、首行缩进
        bodyPara.LineSpacingRule = PageOffice.WordWriter.WdLineSpacing.wdLineSpaceAtLeast;
        bodyPara.Alignment       = PageOffice.WordWriter.WdParagraphAlignment.wdAlignParagraphLeft;
        bodyPara.FirstLineIndent = 21;

        //第二段
        PageOffice.WordWriter.DataRegion body2 = doc.CreateDataRegion("PO_body2", PageOffice.WordWriter.DataRegionInsertType.After, "PO_body");
        body2.Font.Bold = false;
        body2.Font.Size = 12;
        body2.Font.Name = "黑体";
        body2.Value     = "套接字是通信的基石,是支持TCP/IP协议的网络通信的基本操作单元。可以将套接字看作不同主机间的进程进行双向通信的端点,它构成了单个主机内及整个网络间的编程界面。套接字存在于通信域中,通信域是为了处理一般的线程通过套接字通信而引进的一种抽象概念。套接字通常和同一个域中的套接字交换数据(数据交换也可能穿越域的界限,但这时一定要执行某种解释程序)。各种进程使用这个相同的域互相之间用Internet协议簇来进行通信。\n";
        //body2.Value ="[image]../images/logo.jpg[/image]";
        PageOffice.WordWriter.ParagraphFormat bodyPara2 = body2.ParagraphFormat;
        bodyPara2.LineSpacingRule = PageOffice.WordWriter.WdLineSpacing.wdLineSpace1pt5;
        bodyPara2.Alignment       = PageOffice.WordWriter.WdParagraphAlignment.wdAlignParagraphLeft;
        bodyPara2.FirstLineIndent = 21;

        //第三段
        PageOffice.WordWriter.DataRegion body3 = doc.CreateDataRegion("PO_body3", PageOffice.WordWriter.DataRegionInsertType.After, "PO_body2");
        body3.Font.Bold  = false;
        body3.Font.Color = Color.FromArgb(0, 128, 128);
        body3.Font.Size  = 14;
        body3.Font.Name  = "华文彩云";
        body3.Value      = "套接字可以根据通信性质分类,这种性质对于用户是可见的。应用程序一般仅在同一类的套接字间进行通信。不过只要底层的通信协议允许,不同类型的套接字间也照样可以通信。套接字有两种不同的类型:流套接字和数据报套接字。\n";
        PageOffice.WordWriter.ParagraphFormat bodyPara3 = body3.ParagraphFormat;
        bodyPara3.LineSpacingRule = PageOffice.WordWriter.WdLineSpacing.wdLineSpaceDouble;
        bodyPara3.Alignment       = PageOffice.WordWriter.WdParagraphAlignment.wdAlignParagraphLeft;
        bodyPara3.FirstLineIndent = 21;

        PageOffice.WordWriter.DataRegion body4 = doc.CreateDataRegion("PO_body4", PageOffice.WordWriter.DataRegionInsertType.After, "PO_body3");
        body4.Value = "[image]doc/logo.png[/image]";
        //body4.Value = "[word]doc/1.doc[/word]";//还可嵌入其他Word文件
        PageOffice.WordWriter.ParagraphFormat bodyPara4 = body4.ParagraphFormat;
        bodyPara4.Alignment = PageOffice.WordWriter.WdParagraphAlignment.wdAlignParagraphCenter;

        //PageOffice组件的使用
        string fileName = "template.doc";

        PageOfficeCtrl1.ServerPage = Request.ApplicationPath + "/pageoffice/server.aspx";
        //隐藏自定义工具栏
        PageOfficeCtrl1.CustomToolbar = false;
        PageOfficeCtrl1.SaveFilePage  = "SaveFile.aspx";
        PageOfficeCtrl1.SetWriter(doc);
        PageOfficeCtrl1.JsFunction_AfterDocumentSaved = "SaveOK()";
        PageOfficeCtrl1.WebOpen(Server.MapPath("doc/") + fileName, PageOffice.OpenModeType.docNormalEdit, "张佚名");
    }
Esempio n. 24
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserName"] == null || Session["UserName"].ToString().Length <= 0)
        {
            Response.Redirect("Login.aspx");
        }

        if (Request.QueryString["ID"] != null && Request.QueryString["ID"].Trim().Length > 0)
        {
            id = Request.QueryString["ID"];
        }
        else
        {
            Response.Redirect("OrderList.aspx");
        }

        LitDate.Text = DateTime.Now.ToShortDateString() + "    " + "星期" + DateTime.Now.DayOfWeek.ToString(("D"));

        string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|demo_excelorder.mdb";
        string strSql           = "select * from OrderMaster where ID = " + id;

        DataSet ds = new DataSet();

        using (OleDbConnection connection = new OleDbConnection(connectionString))
        {
            try
            {
                connection.Open();
                OleDbDataAdapter command = new OleDbDataAdapter(strSql, connection);
                command.Fill(ds, "ds");
                connection.Close();
            }
            catch (System.Data.OleDb.OleDbException ex)
            {
                throw new Exception(ex.Message);
            }
        }

        PageOffice.ExcelWriter.Workbook workBook = new PageOffice.ExcelWriter.Workbook();
        workBook.DisableSheetDoubleClick = true;
        workBook.DisableSheetRightClick  = true;
        PageOffice.ExcelWriter.Sheet sheet = workBook.OpenSheet("销售订单");
        if (ds != null)
        {
            DataTable dt = ds.Tables[0];
            if (dt.Rows.Count > 0)
            {
                #region 客户信息
                sheet.OpenCell("D5").Value  = dt.Rows[0]["CustName"].ToString();
                sheet.OpenCell("I5").Value  = dt.Rows[0]["OrderNum"].ToString();
                sheet.OpenCell("D6").Value  = dt.Rows[0]["CustDistrict"].ToString();
                sheet.OpenCell("I6").Value  = dt.Rows[0]["OrderDate"].ToString();
                sheet.OpenCell("D18").Value = dt.Rows[0]["MakerName"].ToString();
                sheet.OpenCell("H18").Value = dt.Rows[0]["SalesName"].ToString();
                #endregion

                #region 产品信息
                strSql = "select * from OrderDetail  where OrderID = " + dt.Rows[0]["ID"];
                DataSet ds2 = new DataSet();
                using (OleDbConnection connection = new OleDbConnection(connectionString))
                {
                    try
                    {
                        connection.Open();
                        OleDbDataAdapter command = new OleDbDataAdapter(strSql, connection);
                        command.Fill(ds2, "ds2");
                        connection.Close();
                    }
                    catch (System.Data.OleDb.OleDbException ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
                if (ds2 != null)
                {
                    DataTable dt2 = ds2.Tables[0];
                    if (dt2.Rows.Count > 0)
                    {
                        PageOffice.ExcelWriter.Table table = sheet.OpenTable("C9:H15");
                        for (int j = 0; j < dt2.Rows.Count; j++)
                        {
                            for (int i = 0; i < table.DataFields.Count; i++)
                            {
                                if (dt2.Rows[j][i + 1] != null)
                                {
                                    table.DataFields[i].Value = dt2.Rows[j][i + 1].ToString();
                                }
                                else
                                {
                                    table.DataFields[i].Value = "";
                                }
                            }
                            int result = 0;
                            if (int.TryParse(dt2.Rows[j]["Quantity"].ToString(), out result) &&
                                int.TryParse(dt2.Rows[j]["Price"].ToString(), out result))
                            {
                                sheet.OpenCell("I" + (9 + j)).Value = (int.Parse(dt2.Rows[j]["Quantity"].ToString()) * int.Parse(dt2.Rows[j]["Price"].ToString())).ToString();
                            }
                            table.NextRow();
                        }
                        table.Close();
                    }
                }
                #endregion
            }
        }
        else
        {
            Response.Write("<script>alert('订单号为" + id + "'的订单信息不存在!);location.href='OrderList.aspx'</script>");
        }
        workBook.DisableSheetSelection = true;
        PageOfficeCtrl1.SetWriter(workBook);
    }