コード例 #1
0
ファイル: FormMain.cs プロジェクト: ie310mu/i3go_codemaker
        private void llOutPathModelJsonService_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string path = tbOutPathJsonService.Text;

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            I3PCUtil.CreateAndWaitProcess("", path, "", false);
        }
コード例 #2
0
ファイル: FormMain.cs プロジェクト: ie310mu/i3go_codemaker
        private void linkLabel6_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string path = goModelOutput.Text;

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            I3PCUtil.CreateAndWaitProcess("", path, "", false);
        }
コード例 #3
0
        private void tsbExcel_Click(object sender, EventArgs e)
        {
            HSSFWorkbook workbook = null;

            using (MemoryStream ms = new MemoryStream(Resource.template))
            {
                workbook = new HSSFWorkbook(ms); // 工作簿
            }
            Dictionary <string, HSSFCellStyle> styleDic = new Dictionary <string, HSSFCellStyle>();
            Dictionary <string, IFont>         fontDic  = new Dictionary <string, IFont>();

            //准备sheet
            var sheetIndex = 0;

            foreach (I3ReportData rd in reportDatas.Datas)
            {
                if (sheetIndex > 0)
                {
                    workbook.CloneSheet(0);
                }
                sheetIndex++;
            }

            sheetIndex = 0;
            foreach (I3ReportData rd in reportDatas.Datas)
            {
                string sheetName = string.IsNullOrEmpty(rd.Name) ? ("sheet" + (sheetIndex + 1).ToString()) : rd.Name;
                //ISheet sheet = workbook.CreateSheet(sheetName);
                ISheet sheet = workbook.GetSheetAt(sheetIndex);
                workbook.SetSheetName(sheetIndex, sheetName);

                //设置列宽
                var colIndex = -1;
                foreach (I3ReportCol col in rd.Cols)
                {
                    colIndex++;
                    if (col.Width == 0)
                    {
                        sheet.SetColumnHidden(colIndex, true);
                    }
                    else
                    {
                        //int width = (int)Math.Ceiling(col.Width * 34.612159);  //向上取整,与excel中保持一致  //34.612159是从ebiao导入excel处获取的
                        //在列旁边按住鼠标不动,可以显示默认单位与像素的对应关系,10单位对应85像素,即1像素对应10/85单位  (好像与excel默认字体有关)
                        //SetColumnWidth的单位是1/256,因此1像素对应10*256/85=30.117647
                        double dw    = (double)col.Width * (double)10 * (double)256 / (double)85;
                        int    width = (int)Math.Ceiling(dw);
                        sheet.SetColumnWidth(colIndex, width);
                    }
                }

                //导出数据
                int rowCount = 0;
                foreach (I3PrintArea area in rd.PrintAreas.Dic.Values)
                {
                    exportAreaToSheet(area, workbook, sheet, ref rowCount, styleDic, fontDic);
                }

                //页面设置  //列宽会有微调导致在excel中左右分页
                sheet.SetMargin(MarginType.RightMargin, rd.PageSetting.PaperRightMarginMM / (float)25.4);
                sheet.SetMargin(MarginType.TopMargin, rd.PageSetting.PaperTopMarginMM / (float)25.4);
                sheet.SetMargin(MarginType.LeftMargin, rd.PageSetting.PaperLeftMarginMM / (float)25.4);
                sheet.SetMargin(MarginType.BottomMargin, rd.PageSetting.PaperBottomMarginMM / (float)25.4);
                sheet.PrintSetup.Landscape = rd.PageSetting.PaperOrientation == PaperOrientation.横向;
                int paperType = rd.PageSetting.GetNPOIPaperType();
                if (paperType == 0)  //自定义,不清楚NPOI中怎样设置,用A4
                {
                    sheet.PrintSetup.PaperSize = 9;
                }
                else if (paperType == -1)  //未打到对应关系
                {
                    sheet.PrintSetup.PaperSize = 9;
                }
                else
                {
                    sheet.PrintSetup.PaperSize = (short)paperType;
                }
                sheet.IsPrintGridlines = true;
                sheet.FitToPage        = false;//默认值是true

                //设置锁定
                sheet.ProtectSheet("{D49C4D85-F46E-456F-9C71-DB7D880B5B04}");
                sheet.IsPrintGridlines = false;  //不设置这个,打印时会打印出空白单元格的网络线(即使没有网格线也会打印)

                sheetIndex++;
            }


            string tmpFileName = getTmpFileName();

            using (FileStream file = new FileStream(tmpFileName, FileMode.Create))
            {
                workbook.Write(file);
                file.Close();
            }
            I3PCUtil.CreateAndWaitProcessByEvent(null, tmpFileName, "", IntPtr.Zero, 0, 0);
        }