Exemplo n.º 1
0
        public static DynamicBookMarker UseDefaultStyle(string startBookMarker, List <double> cellWidths, string[,] datas)
        {
            DynamicBookMarker retValue = new DynamicBookMarker();

            retValue.StartBookMarker = startBookMarker;
            retValue.HasHeader       = true;
            retValue.CellWidths      = cellWidths;
            retValue.Datas           = datas;
            retValue.HeaderSetting   = new RowSetting
            {
                BackgroundColor = System.Drawing.Color.FromArgb(93, 93, 93),
                FontColor       = System.Drawing.Color.White,
                FontName        = "Songti SC",
                FontSize        = 8,
                Bold            = true
            };
            retValue.BodySetting = new RowSetting
            {
                BackgroundColor = System.Drawing.Color.White,
                FontColor       = System.Drawing.Color.Black,
                FontName        = "微软雅黑",
                FontSize        = 6,
                Bold            = false
            };
            return(retValue);
        }
Exemplo n.º 2
0
        public string Convert(string inputFilePath,
                              string outputFilePath,
                              List <BookMarker> bookMarkers,
                              DynamicBookMarker dynamicData,
                              string signatureKeyPath = null,
                              string posText          = null)
        {
            string inputExt  = GetFileExt(inputFilePath);
            string outputExt = GetFileExt(outputFilePath);

            IFileConverter fileConverter = SatisfiedBy(
                inputExt,
                outputExt);

            if (fileConverter == null)
            {
                throw new InvalidOperationException(string.Format("未找到从{0}转到{1}的文件转换器", inputExt, outputExt));
            }
            fileConverter.Convert(inputFilePath, outputFilePath, bookMarkers, dynamicData);
            FileInfo fi          = new FileInfo(outputFilePath);
            var      resourceKey = fi.Name;
            var      finalPath   = outputFilePath;

            if (signatureKeyPath != null && posText != null)
            {
                string savePath = Path.Combine(fi.DirectoryName, sigPrefix + fi.Name);
                fileConverter.Signature(outputFilePath, savePath, signatureKeyPath, posText);

                fi          = new FileInfo(savePath);
                resourceKey = fi.Name;
                finalPath   = savePath;
            }

            resourceManager.Put(resourceKey, File.Open(resourceKey, FileMode.Open));
            File.Delete(finalPath);
            return(finalPath);
        }
Exemplo n.º 3
0
        public void Convert(string inputFilePath, string outputFilePath, List <BookMarker> bookMarkers, DynamicBookMarker dynamicData)
        {
            Document document = new Document(inputFilePath);

            if (bookMarkers != null)
            {
                bookMarkers.ForEach(p => document.Range.Replace(p.MarkerName, p.ReplaceText, false, false));
            }
            if (dynamicData != null)
            {
                DocumentBuilder docBuilde = new DocumentBuilder(document);
                docBuilde.MoveToBookmark(dynamicData.StartBookMarker);
                var lineCount = dynamicData.Datas.GetLength(0);
                var colCount  = dynamicData.Datas.GetLength(1);
                for (int i = 0; i < lineCount; i++)
                {
                    for (int j = 0; j < colCount; j++)
                    {
                        docBuilde.InsertCell();//添加一个单元格
                        var font = docBuilde.Font;
                        DynamicBookMarker.RowSetting rowSetting;
                        if (dynamicData.HasHeader && i == 0)
                        {
                            rowSetting = dynamicData.HeaderSetting;
                        }
                        else
                        {
                            rowSetting = dynamicData.BodySetting;
                        }
                        docBuilde.CellFormat.Shading.BackgroundPatternColor = rowSetting.BackgroundColor;//设置列头单元格背景色
                        font.Color = rowSetting.FontColor;
                        font.Name  = rowSetting.FontName;
                        font.Size  = rowSetting.FontSize;
                        font.Bold  = rowSetting.Bold;

                        docBuilde.CellFormat.Width             = dynamicData.CellWidths[j];    //获取列头的宽度
                        docBuilde.CellFormat.Borders.LineStyle = LineStyle.Single;             //边框样式
                        docBuilde.CellFormat.Borders.Color     = Color.Black;                  //边框颜色
                        docBuilde.CellFormat.VerticalMerge     = CellMerge.None;
                        docBuilde.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; //垂直居中对齐
                        docBuilde.ParagraphFormat.Alignment    = ParagraphAlignment.Center;    //水平居中对齐
                        docBuilde.Write(dynamicData.Datas[i, j]);                              //单元格写入数据
                    }
                    docBuilde.EndRow();                                                        //添加行结束
                }
            }
            document.Save(outputFilePath, SaveFormat.Pdf);
        }
Exemplo n.º 4
0
 public void Convert(string inputFilePath, string outputFilePath, DynamicBookMarker dynamicData)
 {
     Convert(inputFilePath, outputFilePath, null, dynamicData);
 }