Ejemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        WordDocument doc = new WordDocument();

        PageOffice.WordWriter.Table table1 = doc.OpenDataRegion("PO_table1").CreateTable(3, 5, WdAutoFitBehavior.wdAutoFitWindow);
        table1.OpenCellRC(1, 1).MergeTo(3, 1);
        table1.OpenCellRC(1, 1).Value = "合并后的单元格";
        //给表格table1中剩余的单元格赋值
        for (int i = 1; i < 4; i++)
        {
            table1.OpenCellRC(i, 2).Value = "AA" + i.ToString();
            table1.OpenCellRC(i, 3).Value = "BB" + i.ToString();
            table1.OpenCellRC(i, 4).Value = "CC" + i.ToString();
            table1.OpenCellRC(i, 5).Value = "DD" + i.ToString();
        }

        //在"PO_table1"后面动态创建一个新的数据区域"PO_table2",用于创建新的一个5行5列的表格table2
        PageOffice.WordWriter.DataRegion drTable2 = doc.CreateDataRegion("PO_table2", DataRegionInsertType.After, "PO_table1");
        PageOffice.WordWriter.Table      table2   = drTable2.CreateTable(5, 5, WdAutoFitBehavior.wdAutoFitWindow);
        //给新表格table2赋值
        for (int i = 1; i < 6; i++)
        {
            table2.OpenCellRC(i, 1).Value = "AA" + i.ToString();
            table2.OpenCellRC(i, 2).Value = "BB" + i.ToString();
            table2.OpenCellRC(i, 3).Value = "CC" + i.ToString();
            table2.OpenCellRC(i, 4).Value = "DD" + i.ToString();
            table2.OpenCellRC(i, 5).Value = "EE" + i.ToString();
        }

        PageOfficeCtrl1.CustomToolbar = false;//隐藏用户自定义工具栏
        PageOfficeCtrl1.SetWriter(doc);
        PageOfficeCtrl1.ServerPage = Request.ApplicationPath + "/pageoffice/server.aspx";
        PageOfficeCtrl1.WebOpen("doc/createTable.doc", PageOffice.OpenModeType.docNormalEdit, "张佚名");
    }
Ejemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        WordDocument doc = new WordDocument();

        PageOffice.WordWriter.Table table1 = doc.OpenDataRegion("PO_T001").OpenTable(1);
        table1.OpenCellRC(1, 1).Value = "PageOffice组件";

        int oldRowCount  = 3; //表格中原有的行数
        int dataRowCount = 5; //要填充数据的行数

        // 扩充表格
        for (int j = 0; j < dataRowCount - oldRowCount; j++)
        {
            table1.InsertRowAfter(table1.OpenCellRC(2, 5));  //在第2行的最后一个单元格下插入新行
        }

        // 填充数据
        int i = 1;

        while (i <= dataRowCount)
        {
            table1.OpenCellRC(i, 2).Value = "AA" + i.ToString();
            table1.OpenCellRC(i, 3).Value = "BB" + i.ToString();
            table1.OpenCellRC(i, 4).Value = "CC" + i.ToString();
            table1.OpenCellRC(i, 5).Value = "DD" + i.ToString();
            i++;
        }
        PageOfficeCtrl1.SetWriter(doc);
        PageOfficeCtrl1.ServerPage = Request.ApplicationPath + "/pageoffice/server.aspx";
        PageOfficeCtrl1.WebOpen("doc/test_table.doc", PageOffice.OpenModeType.docNormalEdit, "张佚名");
    }
Ejemplo n.º 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //***************************卓正PageOffice组件的使用********************************
        WordDocument doc = new WordDocument();
        //打开数据区域
        DataRegion dTable = doc.OpenDataRegion("PO_table");

        //设置数据区域可编辑性
        dTable.Editing = true;
        //打开数据区域中的表格,OpenTable(index)方法中的index为word文档中表格的下标,从1开始
        PageOffice.WordWriter.Table table1 = doc.OpenDataRegion("PO_Table").OpenTable(1);
        // 给表头单元格赋值
        table1.OpenCellRC(1, 2).Value = "产品1";
        table1.OpenCellRC(1, 3).Value = "产品2";
        table1.OpenCellRC(2, 1).Value = "A部门";
        table1.OpenCellRC(3, 1).Value = "B部门";

        PageOfficeCtrl1.SetWriter(doc);

        //添加自定义按钮
        PageOfficeCtrl1.AddCustomToolButton("保存", "Save", 1);
        PageOfficeCtrl1.AddCustomToolButton("全屏/还原", "IsFullScreen", 4);
        //设置服务器页面
        PageOfficeCtrl1.ServerPage = Request.ApplicationPath + "/pageoffice/server.aspx";
        //设置保存页
        PageOfficeCtrl1.SaveDataPage = "SaveData.aspx";
        //设置文档打开方式
        PageOfficeCtrl1.WebOpen("doc/test.doc", PageOffice.OpenModeType.docSubmitForm, "张佚名");
    }
Ejemplo n.º 4
0
    public void Page_Load(object sender, EventArgs e)
    {
        FilePath = Request.ApplicationPath + "WordDeleteRow/doc";
        WordDocument doc = new WordDocument();

        PageOffice.WordWriter.Table table1 = doc.OpenDataRegion("PO_table").OpenTable(1);
        Cell cell = table1.OpenCellRC(2, 1);

        //删除坐标为(2,1)的单元格所在行
        table1.RemoveRowAt(cell);
        PageOfficeCtrl1.CustomToolbar = false;
        PageOfficeCtrl1.SetWriter(doc);
        PageOfficeCtrl1.ServerPage = Request.ApplicationPath + "/pageoffice/server.aspx";
        PageOfficeCtrl1.WebOpen("doc/test_table.doc", PageOffice.OpenModeType.docNormalEdit, "张佚名");
    }
Ejemplo 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, "张三");
    }
Ejemplo n.º 6
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");
                //打开Table
                PageOffice.WordWriter.Table table = datareg.OpenTable(1);
                ////给单元格赋值
                table.OpenCellRC(2, 1).Value = reader["ID"].ToString();
                table.OpenCellRC(2, 2).Value = reader["UserName"].ToString();
                table.OpenCellRC(2, 3).Value = reader["DeptName"].ToString();

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

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

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

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

                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.docReadOnly, "someBody");
    }
Ejemplo n.º 7
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");
    }