public async Task <ActionResult> SaveData()

        {
            //-----------  PageOffice 服务器端编程开始  -------------------//
            PageOfficeNetCore.WordReader.WordDocument doc = new PageOfficeNetCore.WordReader.WordDocument(Request, Response);

            await doc.LoadAsync();

            PageOfficeNetCore.WordReader.DataRegion dataReg = doc.OpenDataRegion("PO_table");
            PageOfficeNetCore.WordReader.Table      table   = dataReg.OpenTable(1);
            //输出提交的table中的数据
            //Response.Write("表格中的各个单元的格数据为:<br/><br/>");
            StringBuilder dataStr = new StringBuilder();

            for (int i = 1; i <= table.RowsCount; i++)
            {
                dataStr.Append("<div style='width:220px;'>");
                for (int j = 1; j <= table.ColumnsCount; j++)
                {
                    dataStr.Append("<div style='float:left;width:70px;border:1px solid red;'>" + table.OpenCellRC(i, j).Value + "</div>");
                }
                dataStr.Append("</div>");
            }
            //Response.Write(dataStr.ToString());
            //向客户端显示提交的数据

            await Response.Body.WriteAsync(Encoding.GetEncoding("GB2312").GetBytes(dataStr.ToString()));

            doc.ShowPage(300, 300);
            doc.Close();
            return(Content("OK"));
        }
        public async Task <ActionResult> SaveData()
        {
            PageOfficeNetCore.WordReader.WordDocument doc = new PageOfficeNetCore.WordReader.WordDocument(Request, Response);
            await doc.LoadAsync();

            PageOfficeNetCore.WordReader.DataRegion dataRegion1 = doc.OpenDataRegion("PO_image");
            //将提取的图片保存到服务器上,图片的名称为:a.jpg

            string webRootPath = _webHostEnvironment.WebRootPath;

            dataRegion1.OpenShape(1).SaveAsJPG(webRootPath + "/ExtractImage/doc/a.jpg");
            //注册编码提供程序
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);


            //UrlEncoder
            doc.CustomSaveResult = HttpUtility.UrlEncode("保存成功,文件保存到:" + "wwwroot/ExtractImage/doc/a.jpg");
            doc.Close();
            return(Content("OK"));
        }
        public async Task <ActionResult> SaveData()
        {
            string content = "";


            PageOfficeNetCore.WordReader.WordDocument doc = new PageOfficeNetCore.WordReader.WordDocument(Request, Response);
            await doc.LoadAsync();

            //获取提交的数值
            PageOfficeNetCore.WordReader.DataRegion dataUserName = doc.OpenDataRegion("PO_userName");
            PageOfficeNetCore.WordReader.DataRegion dataDeptName = doc.OpenDataRegion("PO_deptName");
            content += "公司名称:" + doc.GetFormField("txtCompany");
            content += "<br/>员工姓名:" + dataUserName.Value;
            content += "<br/>部门名称:" + dataDeptName.Value;

            await Response.Body.WriteAsync(Encoding.GetEncoding("GB2312").GetBytes(content));

            doc.ShowPage(400, 300);
            doc.Close();
            return(Content("OK"));
        }
Beispiel #4
0
        public async Task <ActionResult> SaveData()
        {
            PageOfficeNetCore.WordReader.WordDocument doc = new PageOfficeNetCore.WordReader.WordDocument(Request, Response);
            await doc.LoadAsync();

            string webRootPath = _webHostEnvironment.WebRootPath;

            Byte[] bWord;

            // 读取数据区域PO_test1中的内容,保存为一个新的word文档:new1.doc
            PageOfficeNetCore.WordReader.DataRegion dr1 = doc.OpenDataRegion("PO_test1");
            bWord = dr1.FileBytes;

            Stream s1 = new FileStream(webRootPath + "/SplitWord/doc/new1.doc", System.IO.FileMode.Create);

            s1.Write(bWord, 0, bWord.Length);
            s1.Close();

            // 读取数据区域PO_test2中的内容,保存为一个新的word文档:new2.doc
            PageOfficeNetCore.WordReader.DataRegion dr2 = doc.OpenDataRegion("PO_test2");
            bWord = dr2.FileBytes;
            Stream s2 = new FileStream(webRootPath + "/SplitWord/doc/new2.doc", System.IO.FileMode.Create);

            s2.Write(bWord, 0, bWord.Length);
            s2.Close();

            // 读取数据区域PO_test3中的内容,保存为一个新的word文档:new3.doc
            PageOfficeNetCore.WordReader.DataRegion dr3 = doc.OpenDataRegion("PO_test3");
            bWord = dr3.FileBytes;
            Stream s3 = new FileStream(webRootPath + "/SplitWord/doc/new3.doc", FileMode.Create);

            s3.Write(bWord, 0, bWord.Length);
            s3.Close();

            doc.Close();
            return(Content("OK"));
        }
        public async Task <ActionResult> SaveData()
        {
            string content = "";

            PageOfficeNetCore.WordReader.WordDocument doc = new PageOfficeNetCore.WordReader.WordDocument(Request, Response);
            await doc.LoadAsync();

            //获取提交的数值
            PageOfficeNetCore.WordReader.DataRegion poName = doc.OpenDataRegion("PO_Name");
            try
            {
                PageOfficeNetCore.WordReader.DataRegion dataDeptName = doc.OpenDataRegion("PO_deptName");
                content += "后台获取 PO_Name的值:" + poName.Value;
            }
            catch
            {
                content += "客户端提交的数据区域中没有包含名称为 PO_Name 的数据区域。";
            }
            await Response.Body.WriteAsync(Encoding.GetEncoding("GB2312").GetBytes(content));

            doc.ShowPage(400, 300);
            doc.Close();
            return(Content("OK"));
        }