public IActionResult Excel()
        {
            PageOfficeNetCore.PageOfficeCtrl pageofficeCtrl = new PageOfficeNetCore.PageOfficeCtrl(Request);
            pageofficeCtrl.ServerPage = "/PageOffice/POServer";

            //定义Workbook对象
            PageOfficeNetCore.ExcelWriter.Workbook workBook = new PageOfficeNetCore.ExcelWriter.Workbook();
            //定义Sheet对象,"Sheet1"是打开的Excel表单的名称
            PageOfficeNetCore.ExcelWriter.Sheet sheet = workBook.OpenSheet("Sheet1");
            //定义Cell对象,给单元格赋值
            PageOfficeNetCore.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);

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

            pageofficeCtrl.Caption = "简单的给Excel赋值";
            //打开Word文档
            pageofficeCtrl.WebOpen("doc/test.xls", PageOfficeNetCore.OpenModeType.xlsNormalEdit, "tom");
            ViewBag.POCtrl = pageofficeCtrl.GetHtmlCode("PageOfficeCtrl1");
            return(View());
        }
Пример #2
0
        public IActionResult Excel()
        {
            PageOfficeNetCore.PageOfficeCtrl pageofficeCtrl = new PageOfficeNetCore.PageOfficeCtrl(Request);
            pageofficeCtrl.ServerPage = "/PageOffice/POServer";

            PageOfficeNetCore.ExcelWriter.Workbook wb    = new PageOfficeNetCore.ExcelWriter.Workbook();
            PageOfficeNetCore.ExcelWriter.Sheet    sheet = wb.OpenSheet("Sheet1");
            //合并单元格
            sheet.OpenTable("B2:F2").Merge();
            PageOfficeNetCore.ExcelWriter.Cell cB2 = sheet.OpenCell("B2");
            cB2.Value = "北京某公司产品销售情况";
            //设置水平对齐方式
            cB2.HorizontalAlignment = PageOfficeNetCore.ExcelWriter.XlHAlign.xlHAlignCenter;
            cB2.ForeColor           = Color.Red;
            cB2.Font.Size           = 16;

            sheet.OpenTable("B4:B6").Merge();//合并单元格
            PageOfficeNetCore.ExcelWriter.Cell cB4 = sheet.OpenCell("B4");
            cB4.Value = "A产品";
            //设置水平对齐方式
            cB4.HorizontalAlignment = PageOfficeNetCore.ExcelWriter.XlHAlign.xlHAlignCenter;
            //设置垂直对齐方式
            cB4.VerticalAlignment = PageOfficeNetCore.ExcelWriter.XlVAlign.xlVAlignCenter;

            sheet.OpenTable("B7:B9").Merge();//合并单元格
            PageOfficeNetCore.ExcelWriter.Cell cB7 = sheet.OpenCell("B7");
            cB7.Value = "B产品";
            cB7.HorizontalAlignment = PageOfficeNetCore.ExcelWriter.XlHAlign.xlHAlignCenter;
            cB7.VerticalAlignment   = PageOfficeNetCore.ExcelWriter.XlVAlign.xlVAlignCenter;

            pageofficeCtrl.SetWriter(wb);

            pageofficeCtrl.AddCustomToolButton("全屏/还原", "IsFullScreen", 4);
            pageofficeCtrl.Caption = "演示:使用程序合并指定的单元格并设置格式和赋值";

            //打开Word文档
            pageofficeCtrl.WebOpen("doc/test.xls", PageOfficeNetCore.OpenModeType.xlsNormalEdit, "tom");
            ViewBag.POCtrl = pageofficeCtrl.GetHtmlCode("PageOfficeCtrl1");
            return(View());
        }
Пример #3
0
        public IActionResult Excel()
        {
            PageOfficeNetCore.PageOfficeCtrl pageofficeCtrl = new PageOfficeNetCore.PageOfficeCtrl(Request);
            pageofficeCtrl.ServerPage = "/PageOffice/POServer";
            pageofficeCtrl.Caption    = "简单的给Excel赋值";
            //定义Workbook对象
            PageOfficeNetCore.ExcelWriter.Workbook workBook = new PageOfficeNetCore.ExcelWriter.Workbook();
            //定义Sheet对象,"Sheet1"是打开的Excel表单的名称
            PageOfficeNetCore.ExcelWriter.Sheet sheet = workBook.OpenSheet("Sheet1");
            //定义Cell对象
            PageOfficeNetCore.ExcelWriter.Cell cellB4 = sheet.OpenCell("B4");
            //给单元格赋值
            cellB4.Value = "1月";
            //设置字体颜色
            cellB4.ForeColor = Color.Red;

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

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

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

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

            pageofficeCtrl.SetWriter(workBook);
            //打开Word文档
            pageofficeCtrl.WebOpen("doc/test.xls", PageOfficeNetCore.OpenModeType.xlsNormalEdit, "tom");
            ViewBag.POCtrl = pageofficeCtrl.GetHtmlCode("PageOfficeCtrl1");
            return(View());
        }
        public IActionResult Excel()
        {
            PageOfficeNetCore.PageOfficeCtrl pageofficeCtrl = new PageOfficeNetCore.PageOfficeCtrl(Request);
            pageofficeCtrl.ServerPage = "/PageOffice/POServer";

            PageOfficeNetCore.ExcelWriter.Workbook worbBook = new PageOfficeNetCore.ExcelWriter.Workbook();
            PageOfficeNetCore.ExcelWriter.Sheet    Sheetl   = worbBook.OpenSheet("Sheet1");
            PageOfficeNetCore.ExcelWriter.Cell     cell1    = Sheetl.OpenCell("A1");
            cell1.Value = "[image]image/logo.jpg[/image]";
            pageofficeCtrl.SetWriter(worbBook);
            //打开Word文档
            pageofficeCtrl.WebOpen("doc/test.xls", PageOfficeNetCore.OpenModeType.xlsNormalEdit, "tom");
            ViewBag.POCtrl = pageofficeCtrl.GetHtmlCode("PageOfficeCtrl1");
            return(View());
        }
        public IActionResult Excel()
        {
            PageOfficeNetCore.PageOfficeCtrl pageofficeCtrl = new PageOfficeNetCore.PageOfficeCtrl(Request);
            pageofficeCtrl.ServerPage = "/PageOffice/POServer";

            PageOfficeNetCore.ExcelWriter.Workbook wb    = new PageOfficeNetCore.ExcelWriter.Workbook();
            PageOfficeNetCore.ExcelWriter.Sheet    sheet = wb.OpenSheet("Sheet1");

            PageOfficeNetCore.ExcelWriter.Cell cC3 = sheet.OpenCell("C3");
            //设置单元格背景样式
            cC3.BackColor           = Color.AntiqueWhite;
            cC3.Value               = "一月";
            cC3.ForeColor           = Color.Green;
            cC3.HorizontalAlignment = PageOfficeNetCore.ExcelWriter.XlHAlign.xlHAlignCenter;

            PageOfficeNetCore.ExcelWriter.Cell cD3 = sheet.OpenCell("D3");
            //设置单元格背景样式
            cD3.BackColor           = Color.AntiqueWhite;
            cD3.Value               = "二月";
            cD3.ForeColor           = Color.Green;
            cD3.HorizontalAlignment = PageOfficeNetCore.ExcelWriter.XlHAlign.xlHAlignCenter;

            PageOfficeNetCore.ExcelWriter.Cell cE3 = sheet.OpenCell("E3");
            //设置单元格背景样式
            cE3.BackColor           = Color.AntiqueWhite;
            cE3.Value               = "三月";
            cE3.ForeColor           = Color.Green;
            cE3.HorizontalAlignment = PageOfficeNetCore.ExcelWriter.XlHAlign.xlHAlignCenter;

            PageOfficeNetCore.ExcelWriter.Cell cB4 = sheet.OpenCell("B4");
            //设置单元格背景样式
            cB4.BackColor           = Color.SkyBlue;
            cB4.Value               = "住房";
            cB4.ForeColor           = Color.Wheat;
            cB4.HorizontalAlignment = PageOfficeNetCore.ExcelWriter.XlHAlign.xlHAlignCenter;

            PageOfficeNetCore.ExcelWriter.Cell cB5 = sheet.OpenCell("B5");
            //设置单元格背景样式
            cB5.BackColor           = Color.Teal;
            cB5.Value               = "三餐";
            cB5.ForeColor           = Color.Wheat;
            cB5.HorizontalAlignment = PageOfficeNetCore.ExcelWriter.XlHAlign.xlHAlignCenter;

            PageOfficeNetCore.ExcelWriter.Cell cB6 = sheet.OpenCell("B6");
            //设置单元格背景样式
            cB6.BackColor           = Color.MediumPurple;
            cB6.Value               = "车费";
            cB6.ForeColor           = Color.Wheat;
            cB6.HorizontalAlignment = PageOfficeNetCore.ExcelWriter.XlHAlign.xlHAlignCenter;

            PageOfficeNetCore.ExcelWriter.Cell cB7 = sheet.OpenCell("B7");
            //设置单元格背景样式
            cB7.BackColor           = Color.SteelBlue;
            cB7.Value               = "通讯";
            cB7.ForeColor           = Color.Wheat;
            cB7.HorizontalAlignment = PageOfficeNetCore.ExcelWriter.XlHAlign.xlHAlignCenter;

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

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

            pageofficeCtrl.SetWriter(wb); // 不要忘记此句代码
            //打开Word文档
            pageofficeCtrl.WebOpen("doc/test.xls", PageOfficeNetCore.OpenModeType.xlsNormalEdit, "tom");
            ViewBag.POCtrl = pageofficeCtrl.GetHtmlCode("PageOfficeCtrl1");
            return(View());
        }