Ejemplo n.º 1
0
        public async Task <ActionResult> SaveData()
        {
            PageOfficeNetCore.ExcelReader.Workbook doc = new PageOfficeNetCore.ExcelReader.Workbook(Request, Response);
            await doc.LoadAsync();

            PageOfficeNetCore.ExcelReader.Sheet sheet = doc.OpenSheet("Sheet1");
            PageOfficeNetCore.ExcelReader.Table table = sheet.OpenTable("B4:D8");
            String content = "";

            while (!table.EOF)
            {
                //获取提交的数值
                //DataFields.Count标识的是table的列数
                if (!table.DataFields.IsEmpty)
                {
                    content += "<br/>月份名称:" + table.DataFields[0].Text;
                    content += "<br/>计划完成量:" + table.DataFields[1].Text;
                    content += "<br/>实际完成量:" + table.DataFields[2].Text;

                    content += "<br/>*********************************************";
                }
                //循环进入下一行
                table.NextRow();
            }
            table.Close();
            await Response.Body.WriteAsync(Encoding.GetEncoding("GB2312").GetBytes(content));

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

            PageOfficeNetCore.ExcelReader.Workbook workBook = new PageOfficeNetCore.ExcelReader.Workbook(Request, Response);
            PageOfficeNetCore.ExcelReader.Sheet    sheet    = workBook.OpenSheet("Sheet1");
            content += "testA1:" + sheet.OpenCellByDefinedName("testA1").Value + "<br/>";
            content += "testB1:" + sheet.OpenCellByDefinedName("testB1").Value + "<br/>";
            await Response.Body.WriteAsync(Encoding.GetEncoding("GB2312").GetBytes(content));

            workBook.ShowPage(500, 400);
            workBook.Close();
            return(Content("OK"));
        }
        public async Task <ActionResult> SaveData()
        {
            PageOfficeNetCore.ExcelReader.Workbook doc = new PageOfficeNetCore.ExcelReader.Workbook(Request, Response);
            await doc.LoadAsync();

            PageOfficeNetCore.ExcelReader.Sheet sheet  = doc.OpenSheet("Sheet1");
            PageOfficeNetCore.ExcelReader.Table tableA = sheet.OpenTable("tableA");
            PageOfficeNetCore.ExcelReader.Table tableB = sheet.OpenTable("tableB");

            StringBuilder dataStr = new StringBuilder();

            dataStr.Append("提交的数据为:<br/><br/>");
            dataStr.Append("<div style='float:left;width:460px;'>");
            dataStr.Append("<div style='float:left;width:150px;'>&nbsp; </div>");
            dataStr.Append("<div style='float:left;width:150px;'>计划完成量</div>");
            dataStr.Append("<div style='float:left;width:150px;'>实际完成量 </div>");
            dataStr.Append("</div>");
            while (!tableA.EOF)
            {
                dataStr.Append("<div style='float:left;width:460px;'>");
                dataStr.Append("<div style='float:left;width:150px;'> A部门:</div>");
                for (int i = 0; i < tableA.DataFields.Count; i++)
                {
                    dataStr.Append("<div style='float:left;width:150px;'>" + tableA.DataFields[i].Value + "</div>");
                }
                dataStr.Append("</div>");
                tableA.NextRow();
            }
            while (!tableB.EOF)
            {
                dataStr.Append("<div style='float:left;width:460px;'>");
                dataStr.Append("<div style='float:left;width:150px;'> B部门:</div>");
                for (int i = 0; i < tableB.DataFields.Count; i++)
                {
                    dataStr.Append("<div style='float:left;width:150px;'>" + tableB.DataFields[i].Value + "</div>");
                }
                dataStr.Append("</div>");
                tableB.NextRow();
            }
            await Response.Body.WriteAsync(Encoding.GetEncoding("GB2312").GetBytes(dataStr.ToString()));

            //向客户端显示提交的数据
            doc.ShowPage(500, 400);
            doc.Close();
            return(Content("OK"));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> SaveData()
        {
            string content = "";


            PageOfficeNetCore.ExcelReader.Workbook workBook = new PageOfficeNetCore.ExcelReader.Workbook(Request, Response);
            await workBook.LoadAsync();

            PageOfficeNetCore.ExcelReader.Sheet sheet = workBook.OpenSheet("Sheet1");
            PageOfficeNetCore.ExcelReader.Table table = sheet.OpenTable("Info");
            int result = 0;

            while (!table.EOF)
            {
                //获取提交的数值
                //DataFields.Count标识的是提交过来的table的列数
                if (!table.DataFields.IsEmpty)
                {
                    content += "<br/>月份名称:" + table.DataFields[0].Text;
                    content += "<br/>计划完成量:" + table.DataFields[1].Text;
                    content += "<br/>实际完成量:" + table.DataFields[2].Text;
                    content += "<br/>累计完成量:" + table.DataFields[3].Text;
                    if (string.IsNullOrEmpty(table.DataFields[2].Text) || !int.TryParse(table.DataFields[2].Text, out result) ||
                        !int.TryParse(table.DataFields[1].Text, out result))
                    {
                        content += "<br/>完成率:0";
                    }
                    else
                    {
                        float f = int.Parse(table.DataFields[2].Text);
                        f        = f / int.Parse(table.DataFields[1].Text);
                        content += "<br/>完成率:" + string.Format("{0:P}", f);
                    }
                    content += "<br/>*********************************************";
                }
                //循环进入下一行
                table.NextRow();
            }
            table.Close();
            await Response.Body.WriteAsync(Encoding.GetEncoding("GB2312").GetBytes(content));

            workBook.ShowPage(500, 400);
            workBook.Close();
            return(Content("OK"));
        }