OpenXml相对于用MS提供的COM组件来生成WORD,有如下优势:

1.相对于MS 的COM组件,因为版本带来的不兼容问题,及各种会生成WORD半途会崩溃的问题.

2.对比填满一张30多页的WORD来说(包含图,表等),用COM组件来生成会占用20秒,Openxml1秒.

3.MS Word软件太贵了,你的客户装的是开源WORD,如LibreOffice,OpenOffice.这样你就只能用Openxml生成的WORD文档,各种支持MS Word都能打开,避免客户机器上安装MS Word.

简单来说OpenXml的各个操作.

首先用OpenXml打开一张报表.

public void CreateOpenXMLFile(string filePath)
        {
            using (WordprocessingDocument objWordDocument = WordprocessingDocument.Create(filePath, WordprocessingDocumentType.Document))
            {
                MainDocumentPart objMainDocumentPart = objWordDocument.AddMainDocumentPart();
                objMainDocumentPart.Document = new Document(new Body());
                Body objBody = objMainDocumentPart.Document.Body;
                //创建一些需要用到的样式,如标题3,标题4,在OpenXml里面,这些样式都要自己来创建的
                //ReportExport.CreateParagraphStyle(objWordDocument);
                SectionProperties sectionProperties = new SectionProperties();
                PageSize pageSize = new PageSize();
                PageMargin pageMargin = new PageMargin();
                Columns columns = new Columns() { Space = "220" };//720
                DocGrid docGrid = new DocGrid() { LinePitch = 100 };//360
                //创建页面的大小,页距,页面方向一些基本的设置,如A4,B4,Letter,
                //GetPageSetting(PageSize,PageMargin);

                //在这里填充各个Paragraph,与Table,页面上第一级元素就是段落,表格.
                objBody.Append(new Paragraph());
                objBody.Append(new Table());
                objBody.Append(new Paragraph());

                //我会告诉你这里的顺序很重要吗?下面才是把上面那些设置放到Word里去.(大家可以试试把这下面的代码放上面,会不会出现打开openxml文件有误,因为内容有误)
                sectionProperties.Append(pageSize, pageMargin, columns, docGrid);
                objBody.Append(sectionProperties);

                //如果有页眉,在这里添加页眉.
                if (IsAddHead)
                {
                    //添加页面,如果有图片,这个图片和上面添加在objBody方式有点不一样,这里搞了好久.
                    //ReportExport.AddHeader(objMainDocumentPart, image);
                }
                objMainDocumentPart.Document.Save();
            }
        }

从这个总纲里,把上面的各个步骤再来仔细说下.

首先是在Openxml创建标题3,标题4.

// 为文档创建段落样式
        public static void CreateParagraphStyle(WordprocessingDocument doc)
        {
            // 进入文档控制样式部分
            StyleDefinitionsPart styleDefinitionsPart;
            styleDefinitionsPart = doc.MainDocumentPart.AddNewPart<StyleDefinitionsPart>();
            Styles root = new Styles();
            root.Save(styleDefinitionsPart);

            Styles styles = styleDefinitionsPart.Styles;
            if (styles == null)
            {
                styleDefinitionsPart.Styles = new Styles();
                styleDefinitionsPart.Styles.Save();
            }

            Style style3 = CreateTitleStyle(3);
            Style style4 = CreateTitleStyle(4);
            // 把样式添加入文档中
            styles.Append(style3);
            styles.Append(style4);
        }

        private static Style CreateTitleStyle(int titleIndex)
        {
            string titleID = titleIndex.ToString();
            string rsid = string.Empty;
            string before = string.Empty;
            string after = string.Empty;
            string line = string.Empty;
            string val = string.Empty;
            int outline = titleIndex - 1;
            if (titleIndex == 3)
            {
                rsid = "00BA1E98";
                before = "130";//"260"
                after = "0";
                line = "286";//"416"
                val = "32";

            }
            else if (titleIndex == 4)
            {
                rsid = "00BA1E98";
                before = "88";
                after = "0";
                line = "288";//"376"
                val = "28";
            }

            Style style2 = new Style() { Type = StyleValues.Paragraph, StyleId = titleID };
            StyleName styleName2 = new StyleName() { Val = "heading " + titleID };
            BasedOn basedOn1 = new BasedOn() { Val = "a" };
            NextParagraphStyle nextParagraphStyle1 = new NextParagraphStyle() { Val = "a" };
            LinkedStyle linkedStyle1 = new LinkedStyle() { Val = titleID + "Char" };
            UIPriority uIPriority1 = new UIPriority() { Val = 9 };
            PrimaryStyle primaryStyle2 = new PrimaryStyle();
            Rsid rsid2 = new Rsid() { Val = rsid };
            style2.Append(styleName2);
            style2.Append(basedOn1);
            style2.Append(nextParagraphStyle1);
            style2.Append(linkedStyle1);
            style2.Append(uIPriority1);
            style2.Append(primaryStyle2);
            style2.Append(rsid2);

            StyleParagraphProperties styleParagraphProperties2 = new StyleParagraphProperties();
            KeepNext keepNext1 = new KeepNext();
            KeepLines keepLines1 = new KeepLines();
            SpacingBetweenLines spacingBetweenLines1 = new SpacingBetweenLines() { Before = before, After = after, Line = line, LineRule = LineSpacingRuleValues.Auto };
            OutlineLevel outlineLevel1 = new OutlineLevel() { Val = outline };
            styleParagraphProperties2.Append(keepNext1);
            styleParagraphProperties2.Append(keepLines1);
            styleParagraphProperties2.Append(spacingBetweenLines1);
            styleParagraphProperties2.Append(outlineLevel1);
            style2.Append(styleParagraphProperties2);

            StyleRunProperties styleRunProperties1 = new StyleRunProperties();
            Bold bold1 = new Bold();
            BoldComplexScript boldComplexScript1 = new BoldComplexScript();
            // Kern kern2 = new Kern() { Val = (UInt32)44U };
            FontSize fontSize2 = new FontSize() { Val = val };
            FontSizeComplexScript fontSizeComplexScript2 = new FontSizeComplexScript() { Val = val };
            styleRunProperties1.Append(bold1);
            styleRunProperties1.Append(boldComplexScript1);
            //styleRunProperties1.Append(kern2);
            styleRunProperties1.Append(fontSize2);
            styleRunProperties1.Append(fontSizeComplexScript2);
            style2.Append(styleRunProperties1);
            return style2;
        }

然后是对页面大小,页面方向,页距设置.(懒的和报表里的一个个对应,里面的页距有很多大家可以精确设置.)

public static void GetPageSetting(ref PageSize pageSize, ref PageMargin pageMargin)
        {
            bool val = IsPaperOrientation;
            string str_paperSize = "Letter";//A4,B4
            UInt32Value width = 15840U;
            UInt32Value height = 12240U;
            int top = 1440;
            UInt32Value left = 1440U;
            if (str_paperSize == "A4")
            {
                width = 16840U;
                height = 11905U;
            }
            else if (str_paperSize == "B4")
            {
                width = 20636U;
                height = 14570U;
            }

            if (!val)
            {
                UInt32Value sweep = width;
                width = height;
                height = sweep;

                int top_sweep = top;
                top = (int)left.Value;
                left = (uint)top_sweep;
            }

            pageSize.Width = width;
            pageSize.Height = height;
            pageSize.Orient = new EnumValue<PageOrientationValues>(val ? PageOrientationValues.Landscape : PageOrientationValues.Portrait);

            pageMargin.Top = top;
            pageMargin.Bottom = top;
            pageMargin.Left = left;
            pageMargin.Right = left;
            pageMargin.Header = (UInt32Value)720U;
            pageMargin.Footer = (UInt32Value)720U;
            pageMargin.Gutter = (UInt32Value)0U;
        }

然后重点来了,大家对各元素如何在OpenXml添加的.

我先说下,在Openxml里相关元素的关系,在Word里,按一下Enter,转一行,对应的一行元素就是Paragraph,那如果一行文字在里面如何存放.Paragraph->Run->Text,图表Paragraph->Run->Drawing,表格Table->TableRow->TableCell->Paragraph->Run->Text与Drawing.在关系上说,还是很简洁的.来看一下具体的操作,我们先定义一个类.对应OpenXML里的基本样式设置.

public class ReportCommon
    {
        public const float defaultSize = 12f;
        public const float H1 = 20f;
        public const float H3 = 16f;
        public const float H4 = 14f;
        private string text = string.Empty;

        public ReportCommon()
        {
            Alignment = -1;
            Size = defaultSize;
        }

        //规定-1左对齐,0中间,1右对齐
        public int Alignment { get; set; }

        public virtual float Size { get; set; }

        public string Text { get; set; }

        public virtual bool IsBold { get; set; }
    }

其中我定义这个类的三个子类,分别是ReportValue:主要是这种A: B,ReportImage:包含一个图片的路径.ReportText:只有一个文本.

private static List<Run> GetRuns(ReportCommon common)
        {
            List<Run> runs = new List<Run>();
            if (common is ReportValue)
            {
                ReportValue reportvalue = common as ReportValue;
                Run r = new Run();
                RunProperties rP = GetRunProperties(reportvalue, true);
                r.Append(rP);
                string text = reportvalue.Text;
                if (text.EndsWith(":"))
                    text = text + " ";
                if (!text.EndsWith(": "))
                    text = text + ": ";
                Text t = CreateText(text);
                r.Append(t);
                runs.Add(r);

                r = new Run();
                rP = GetRunProperties(reportvalue, false);
                r.Append(rP);
                r.Append(CreateText(reportvalue.Value));
                runs.Add(r);
            }
            else if (common is ReportImage)
            {
                ReportImage reportImage = common as ReportImage;
                Run r = new Run();
                RunProperties rP = GetRunProperties(reportImage);
                Drawing image = GetImageToBody(reportImage.RId, reportImage.Width * 600, reportImage.Height * 800);
                //Drawing image = new Drawing();
                //image.Append(new A.Blip() { Embed = new StringValue(reportImage.RId) });
                r.Append(rP);
                r.Append(image);
                runs.Add(r);
            }
            else if (common is ReportText)
            {
                Run r = new Run();
                RunProperties rP = GetRunProperties(common);
                r.Append(rP);
                r.Append(CreateText(common.Text));
                runs.Add(r);
            }
            return runs;
        }

看了这里,问题是不是越来越多.图片具体操作先不说.上面的RunProperties,与CreateText分别是指什么.

RunProperties是指包含这段Text,你要设置的一些字体大小,颜色,文本对齐设置.

而CreateText是因为我们在Openxml你在后面加个空格,而会给你过滤掉,空格要对应到XML的具体设置,看如下代码.

public static RunProperties GetRunProperties(ReportCommon common, bool bBold = false)
        {
            RunProperties rPr = new RunProperties();
            //Color color = new Color() { Val = "FF0000" }; // the color is red
            RunFonts rFont = new RunFonts();
            rFont.Ascii = "Arial"; // the font is Arial
            //rPr.Append(color);
            //rPr.Append(rFont);
            if (common.IsBold || bBold)
                rPr.Append(new Bold()); // it is Bold
            //TextAlignment
            rPr.Append(new FontSize() { Val = new StringValue((common.Size * 2).ToString()) }); //font size (in 1/72 of an inch)
            return rPr;
        }
  private static Text CreateText(string text)
        {
            if (text == null)
                text = string.Empty;
            Text t = new Text(text);
            if (text.EndsWith(" "))
            {
                t.Space = new EnumValue<SpaceProcessingModeValues>(SpaceProcessingModeValues.Preserve);
            }
            if (text.StartsWith(" "))
            {
                t.Space = new EnumValue<SpaceProcessingModeValues>(SpaceProcessingModeValues.Default);
            }
            return t;
        }

不知这么多代码大家看烦没,因为我这人喜欢不是业务与大纲的事,都喜欢直接看代码来说,比人讲的清楚.所以讲的时候也喜欢,直接上代码.废话不说了,说下图片的问题,Openxml插入图片比较麻烦,先贴一段代码.

private static Drawing GetImageToBody(string relationshipId, int x = 914400, int y = 360000)
        {
            // Define the reference of the image.
            var element =
                 new Drawing(
                     new DW.Inline(
                         new DW.Extent() { Cx = x, Cy = y },
                         new DW.EffectExtent()
                         {
                             LeftEdge = 0L,
                             TopEdge = 0L,
                             RightEdge = 0L,
                             BottomEdge = 0L
                         },
                         new DW.DocProperties()
                         {
                             Id = (UInt32Value)1U,
                             Name = "Picture 1"
                         },
                         new DW.NonVisualGraphicFrameDrawingProperties(
                             new A.GraphicFrameLocks() { NoChangeAspect = true }),
                         new A.Graphic(
                             new A.GraphicData(
                                 new PIC.Picture(
                                     new PIC.NonVisualPictureProperties(
                                         new PIC.NonVisualDrawingProperties()
                                         {
                                             Id = (UInt32Value)0U,
                                             Name = "New Bitmap Image.jpg"
                                         },
                                         new PIC.NonVisualPictureDrawingProperties()),
                                     new PIC.BlipFill(
                                         new A.Blip(
                                             new A.BlipExtensionList(
                                                 new A.BlipExtension()
                                                 {
                                                     Uri =
                                                       "{28A0092B-C50C-407E-A947-70E740481C1C}"
                                                 })
                                         )
                                         {
                                             Embed = relationshipId,
                                             CompressionState =
                                             A.BlipCompressionValues.Print
                                         },
                                         new A.Stretch(
                                             new A.FillRectangle())),
                                     new PIC.ShapeProperties(
                                         new A.Transform2D(
                                             new A.Offset() { X = 0L, Y = 0L },
                                             new A.Extents() { Cx = x, Cy = y }),
                                         new A.PresetGeometry(
                                             new A.AdjustValueList()
                                         ) { Preset = A.ShapeTypeValues.Rectangle }))
                             ) { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" })
                     )
                     {
                         DistanceFromTop = (UInt32Value)0U,
                         DistanceFromBottom = (UInt32Value)0U,
                         DistanceFromLeft = (UInt32Value)0U,
                         DistanceFromRight = (UInt32Value)0U,
                         EditId = "50D07946"
                     });
            // Append the reference to body, the element should be in a Run.
            var blip = element.Descendants<DocumentFormat.OpenXml.Drawing.Blip>()
               .FirstOrDefault<DocumentFormat.OpenXml.Drawing.Blip>();
            return element;
        }

这段代码里,东东比较多,大家主要看这一节, Embed = relationshipId,也是参数里要求传入的,我们可以这么理解,在OpenXML插入一张电脑的图片,插入数据到word后,word然后把保存这个图片的一个标识量给我们,让我们来用,就是relationshipId.说到这,我们好像还没看如何把一张路径下的图片插入word.如下

public static void CreateImageRid(ReportImage reportImage, MainDocumentPart objMainDocumentPart)
        {
            ImagePartType imagetype = ImagePartType.Jpeg;
            FileInfo newImg = new FileInfo(reportImage.Value);
            ImagePart newImgPart = objMainDocumentPart.AddImagePart(imagetype);
            //插入图片数据到Word里去.
            using (FileStream stream = newImg.OpenRead())
            {
                newImgPart.FeedData(stream);
            }
            //Word返回给我们插入数据的标识符.
            reportImage.RId = objMainDocumentPart.GetIdOfPart(newImgPart);
        }

这里图片插入有先后关系,要先调用上面这段,插入数据到word,然后才能调用上上段的那段代码来生成Drawing元素.

大家如果要把图片的宽度,设为当前Word的可用宽度.Int32Value width = (int)(pageSize.Width - pageMargin.Right - pageMargin.Left);

好吧,大家会发现上上段那里的长度特大,这里发现这里的值要很大才能显现比较好看的图片,一般我在原来的基础宽度*600,基础长度*800.原因吗,我也不清楚,有些猜测,没有验证就不说了,这个要求OpenXML生成报表比较急,我把这几天所有操作先总结一下.后面再来修改,如果有知道的道友,不妨说一下.

在这里,文字与图片如何生成Paragraph就很简单了.

public static Paragraph GetParagraph(ReportCommon common)
        {
            Paragraph p = new Paragraph();
            ParagraphProperties pPr = GetParagraphProperties(common);
            p.Append(pPr);
            List<Run> run = GetRuns(common);
            foreach (var r in run)
            {
                p.Append(r);
            }
            return p;
        }

好吧,最后说到如何在OpenXML生成一张表.生成图表我用的基础数据是List<List<string>>,上面的 ReportTable数据就放在这个里面.当然还有一些基本的定义属性就不说.具体如下看代码.

public static Table GetParagraph(ReportTable reportTable, Int32Value width)
        {
            Table table = new Table();
            TableProperties tblProp = new TableProperties(
                new TableBorders(
                    new TopBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
                    new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
                    new LeftBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
                    new RightBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
                    new InsideHorizontalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
                    new InsideVerticalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 }
                 )
            );
            tblProp.TableWidth = new TableWidth() { Width = width.ToString(), Type = TableWidthUnitValues.Dxa };
            table.Append(tblProp);
            int count = reportTable.Value.Count;
            int cols = reportTable.Column;
            int j = 0;
            foreach (List<string> strs in reportTable.Value)
            {
                TableRow row = new TableRow();
                for (int i = 0; i < cols; i++)
                {
                    TableCell cell = new TableCell();
                    TableCellProperties tableCellProperties = new TableCellProperties();
                    TableCellMargin margin = new TableCellMargin();
                    margin.LeftMargin = new LeftMargin() { Width = "100", Type = TableWidthUnitValues.Dxa };
                    margin.RightMargin = new RightMargin() { Width = "100", Type = TableWidthUnitValues.Dxa };
                    tableCellProperties.Append(margin);
                    Paragraph par = new Paragraph();
                    Run run = new Run();
                    if (j == 0 && reportTable.IsHaveColumn)
                    {
                        RunProperties rPr = new RunProperties();
                        rPr.Append(new Bold());
                        run.Append(rPr);
                    }
                    if (strs.Count != cols && i >= strs.Count - 1)
                    {
                        HorizontalMerge verticalMerge = new HorizontalMerge();
                        if (i == strs.Count - 1)
                        {
                            RunProperties rPr = new RunProperties();
                            rPr.Append(new Bold());
                            run.Append(rPr);
                            verticalMerge.Val = MergedCellValues.Restart;
                            run.Append(CreateText(strs[i]));
                        }
                        else
                        {
                            verticalMerge.Val = MergedCellValues.Continue;
                        }
                        tableCellProperties.Append(verticalMerge);
                    }
                    else
                    {
                        run.Append(CreateText(strs[i]));
                    }
                    par.Append(run);
                    cell.Append(tableCellProperties);
                    cell.Append(par);
                    row.Append(cell);
                }
                j++;
                table.Append(row);
            }

            return table;
        }

代码可以简单的多,只是因为有一些要求,比如你表每行是5个数据,但是有一行,数据只有四个,有二个表格合并了,这里会默认把最后二格合并,具体意思大家可以改改代码看.

好吧,到这里,就差不多,元素添加完后,然后是把相关页面大小的设置加到objBody,最后是添加页眉.

public static void AddHeader(MainDocumentPart mainDocPart, ReportImage reportImge)
        {
            // Delete the existing header parts.
            mainDocPart.DeleteParts(mainDocPart.HeaderParts);

            // Create a new header part and get its relationship id.
            HeaderPart newHeaderPart = mainDocPart.AddNewPart<HeaderPart>();
            string rId = mainDocPart.GetIdOfPart(newHeaderPart);

            ImagePart imagepart = newHeaderPart.AddImagePart(ImagePartType.Jpeg);
            FileInfo newImg = new FileInfo(reportImge.Value);
            using (FileStream stream = newImg.OpenRead())
            {
                imagepart.FeedData(stream);
            }
            string imageRID = newHeaderPart.GetIdOfPart(imagepart);
            reportImge.RId = imageRID;
            Header header = GeneratePageHeaderPart(reportImge);
            header.Save(newHeaderPart);

            foreach (SectionProperties sectProperties in
              mainDocPart.Document.Descendants<SectionProperties>())
            {
                //  Delete any existing references to headers.
                foreach (HeaderReference headerReference in
                  sectProperties.Descendants<HeaderReference>())
                    sectProperties.RemoveChild(headerReference);

                HeaderReference newHeaderReference =
                  new HeaderReference() { Id = rId, Type = HeaderFooterValues.Default };
                sectProperties.Append(newHeaderReference);
            }
            header.Save();
        }

        // Creates an header instance and adds its children.
        private static Header GeneratePageHeaderPart(ReportImage reportImge)
        {
            var runs = GetRuns(reportImge);
            Paragraph paragraph = new Paragraph();
            paragraph.Append(GetParagraphProperties(reportImge));
            foreach (var run in runs)
            {
                paragraph.Append(run);
            }
            paragraph.Append(new Run(new Text() { Text = "" }));
            Header header = new Header();
            header.Append(paragraph);
            return header;
        }

上面的代码主要注意,Image所指的路径存放的和在前面的Document里不一样,这里存放在Header里,从Word文件解压来说,二都是不同的XML文档,你把图片数据写在Document里,得到的标识符在Header是空的.

好了.OpenXML的主要操作都在这了,但是大家如果想生成这种样式,应该如何处理?

上面每一个元素如 Payload Mass (LBS): 0.22046,就是前面的ReportValue,如何以这种对齐方式来插入了?引入一个新的结构,ReportValueList,主要就是ReportValue的键表信息.

public static List<Paragraph> GetParagraph(ReportValueList valueList, Int32Value width, int column = 2)
        {
            if (column < 1)
                column = 1;
            List<Paragraph> list = new List<Paragraph>();
            int currentcolumn = 0;
            Paragraph currentParagraph = null;
            foreach (var reportvalue in valueList.Values)
            {
                reportvalue.Size = valueList.Size;
                if (currentcolumn == 0)
                {
                    currentParagraph = new Paragraph();
                    ParagraphProperties pPr = new ParagraphProperties();
                    //添加标签类
                    Tabs tabs = new Tabs();
                    Int32Value eachWidth = width / (new Int32Value(column));
                    for (int i = 1; i < column; i++)
                    {
                        TabStop stop = new TabStop();
                        stop.Val = new EnumValue<TabStopValues>(TabStopValues.Left);
                        stop.Position = eachWidth * i;
                        tabs.Append(stop);
                    }
                    pPr.Append(tabs);
                    currentParagraph.Append(pPr);
                    list.Add(currentParagraph);
                }
                List<Run> runs = GetRuns(reportvalue);
                foreach (var run in runs)
                {
                    currentParagraph.Append(run);
                }
                currentcolumn++;
                if (currentcolumn < column)
                {
                    Run run = new Run();
                    run.Append(new TabChar());
                    currentParagraph.Append(run);
                }
                if (currentcolumn >= column)
                {
                    currentcolumn = 0;
                }
            }
            return list;
        }

主要是对元素TabStop的运用,仔细的大家可以去查查文档

写到这里,忘记写要用到的命名空间.

using A = DocumentFormat.OpenXml.Drawing;
using PIC = DocumentFormat.OpenXml.Drawing.Pictures;
using DW = DocumentFormat.OpenXml.Drawing.Wordprocessing;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;

这个就到这里了.下面如果有时间,我会讲一下,如果对整张报表来进行模版化,意思是在word里的每一个表,一个图片,一个文字,在软件上用生成的结果来替换相应的元素.

OpenXml操作Word的一些操作总结. - 天天不在的更多相关文章

  1. OpenXml操作Word的一些操作总结.

    OpenXml操作Word的一些操作总结. OpenXml相对于用MS提供的COM组件来生成WORD,有如下优势: 1.相对于MS 的COM组件,因为版本带来的不兼容问题,及各种会生成WORD半途会崩 ...

  2. OpenXml操作Word的一些操作总结.无word组件生成word.

    OpenXml相对于用MS提供的COM组件来生成WORD,有如下优势: 1.相对于MS 的COM组件,因为版本带来的不兼容问题,及各种会生成WORD半途会崩溃的问题. 2.对比填满一张30多页的WOR ...

  3. OpenXml操作Word的一些操作总结.无word组件生成word.(转)

    http://www.cnblogs.com/zhouxin/p/3174936.html OpenXml相对于用MS提供的COM组件来生成WORD,有如下优势: 1.相对于MS 的COM组件,因为版 ...

  4. OpenXML操作word

    OpenXML概述 项目中经常需要操作word,之前的方式是采用COM接口,这个接口很不稳定,经常报错.现在开始采用OpenXML.OpenXML(OOXML)是微软在Office 2007中提出的一 ...

  5. c#操作word表格

    http://www.webshu.net/jiaocheng/programme/ASPNET/200804/6499.html <% if request("infoid" ...

  6. Delphi对Word一些进阶操作

    利用VBA 编程,可以使许多日常的任务自动完成,使用户的工作更有效率. 1.在启动时显示打开对话框 一般情况下启动Word,Word 会认为是创建一个新文档.如果只是想打开一个旧文档进行编辑,在Wor ...

  7. python操作word入门

    1.安装pywin32 http://sourceforge.net/projects/pywin32 在files里去找适合你的python版本.截止此文,最新版本是pywin32-219快捷路径: ...

  8. C#中操作Word(1)—— word对象模型介绍

    一.开发环境布置 C#中添加对Word的支持,只需添加对Microsoft.Office.Interop.Word的命名空间,如下图所示,右键点击“引用”,在弹出的“添加引用”对话框中选中COM标签页 ...

  9. C#操作Word的超详细总结

    本文中用C#来操作Word,包括: 创建Word: 插入文字,选择文字,编辑文字的字号.粗细.颜色.下划线等: 设置段落的首行缩进.行距: 设置页面页边距和纸张大小: 设置页眉.页码: 插入图片,设置 ...

随机推荐

  1. Android入门(八)广播

    原文链接:http://www.orlion.ga/572/ 一.广播机制 Android中的每个应用程序都可以对自己感兴趣的广播进行注册,这样该程序就只会接收到自己所关心的广播内容,这些广 播可能是 ...

  2. CLR via C#深解笔记三 - 基元类型、引用类型和值类型 | 类型和成员基础 | 常量和字段

    编程语言的基元类型   某些数据类型如此常用,以至于许多编译器允许代码以简化的语法来操纵它们. System.Int32 a = new System.Int32();  // a = 0 a = 1 ...

  3. javascript表单操作方法

    一.Form元素 相关属性: 1,action属性 2,elements属性 3,length属性 4,name属性 5, method属性 如果多个表单字段的name属性相同,那么提交的value就 ...

  4. [MEAN+ Webstrom] First API -- 2.Debug Node.js RESTful application

    Using WebStrom can easily debug the Node applcation. For example, we have an Node+Express applicatio ...

  5. 三.CSS层叠机制

    概述 层叠就是对样式的层叠.是某种样式在样式表中逐层叠加的过程.让浏览器对某个标签特定属性值的多个来源,最终确定使用那个值.层叠是整个CSS的核心机制. HTML文档样式的来源 1.浏览器默认样式,每 ...

  6. CSS案例

    1.美团网效果 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> ...

  7. Leetcode刷题第001天

    一.合并两个有序链表 [题目]206. 反转链表 /** * Definition for singly-linked list. * struct ListNode { * int val; * L ...

  8. C#跨窗体传值的几种方法分析(很详细)

    创建一个Winform窗体应用程序项目,然后添加一个Form2窗体. 在Form1和Form2中各添加一个textBox和button: 单击Form1中的button1,弹出Form2,然后要做的就 ...

  9. Django开发环境搭建

    最近笔者使用了Django框架作为项目model层的数据对象处理. 关于Django的开发环境,需要安装以下内容: 1.安装python 2.安装VCForPython27.msi 3.安装pycha ...

  10. java自动探测文件的字符编码

    Mozilla有一个C++版的自动字符集探测算法代码,然后sourceforge上有人将其改成java版的~~ 主页:http://jchardet.sourceforge.net/ jchardet ...