当前位置: 首页>>代码示例>>C#>>正文


C# Application.InchesToPoints方法代码示例

本文整理汇总了C#中Microsoft.Office.Interop.Word.Application.InchesToPoints方法的典型用法代码示例。如果您正苦于以下问题:C# Application.InchesToPoints方法的具体用法?C# Application.InchesToPoints怎么用?C# Application.InchesToPoints使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Office.Interop.Word.Application的用法示例。


在下文中一共展示了Application.InchesToPoints方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            object oMissing = System.Reflection.Missing.Value;
            object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */

            //Start Word and create a new document.
            Word._Application oWord;
            Word._Document oDoc;
            oWord = new Word.Application();
            oWord.Visible = true;
            oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,
                ref oMissing, ref oMissing);

            //Insert a paragraph at the beginning of the document.
            Word.Paragraph oPara1;
            oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);
            oPara1.Range.Text = "Heading 1";
            oPara1.Range.Font.Bold = 1;
            oPara1.Format.SpaceAfter = 24;    //24 pt spacing after paragraph.
            oPara1.Range.InsertParagraphAfter();

            //Insert a paragraph at the end of the document.
            Word.Paragraph oPara2;
            object oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oPara2 = oDoc.Content.Paragraphs.Add(ref oRng);
            oPara2.Range.Text = "Heading 2";
            oPara2.Format.SpaceAfter = 6;
            oPara2.Range.InsertParagraphAfter();

            //Insert another paragraph.
            Word.Paragraph oPara3;
            oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oPara3 = oDoc.Content.Paragraphs.Add(ref oRng);
            oPara3.Range.Text = "This is a sentence of normal text. Now here is a table:";
            oPara3.Range.Font.Bold = 0;
            oPara3.Format.SpaceAfter = 24;
            oPara3.Range.InsertParagraphAfter();

            //Insert a 3 x 5 table, fill it with data, and make the first row
            //bold and italic.
            Word.Table oTable;
            Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oTable = oDoc.Tables.Add(wrdRng, 3, 5, ref oMissing, ref oMissing);
            oTable.Range.ParagraphFormat.SpaceAfter = 6;
            int r, c;
            string strText;
            for (r = 1; r <= 3; r++)
                for (c = 1; c <= 5; c++)
                {
                    strText = "r" + r + "c" + c;
                    oTable.Cell(r, c).Range.Text = strText;
                }
            oTable.Rows[1].Range.Font.Bold = 1;
            oTable.Rows[1].Range.Font.Italic = 1;

            //Add some text after the table.
            Word.Paragraph oPara4;
            oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oPara4 = oDoc.Content.Paragraphs.Add(ref oRng);
            oPara4.Range.InsertParagraphBefore();
            oPara4.Range.Text = "And here's another table:";
            oPara4.Format.SpaceAfter = 24;
            oPara4.Range.InsertParagraphAfter();

            //Insert a 5 x 2 table, fill it with data, and change the column widths.
            wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oTable = oDoc.Tables.Add(wrdRng, 5, 2, ref oMissing, ref oMissing);
            oTable.Range.ParagraphFormat.SpaceAfter = 6;
            for (r = 1; r <= 5; r++)
                for (c = 1; c <= 2; c++)
                {
                    strText = "r" + r + "c" + c;
                    oTable.Cell(r, c).Range.Text = strText;
                }
            oTable.Columns[1].Width = oWord.InchesToPoints(2); //Change width of columns 1 & 2
            oTable.Columns[2].Width = oWord.InchesToPoints(3);

            //Keep inserting text. When you get to 7 inches from top of the
            //document, insert a hard page break.
            object oPos;
            double dPos = oWord.InchesToPoints(7);
            oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range.InsertParagraphAfter();
            do
            {
                wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                wrdRng.ParagraphFormat.SpaceAfter = 6;
                wrdRng.InsertAfter("A line of text");
                wrdRng.InsertParagraphAfter();
                oPos = wrdRng.get_Information
                               (Word.WdInformation.wdVerticalPositionRelativeToPage);
            }
            while (dPos >= Convert.ToDouble(oPos));
            object oCollapseEnd = Word.WdCollapseDirection.wdCollapseEnd;
            object oPageBreak = Word.WdBreakType.wdPageBreak;
            wrdRng.Collapse(ref oCollapseEnd);
            wrdRng.InsertBreak(ref oPageBreak);
            wrdRng.Collapse(ref oCollapseEnd);
            wrdRng.InsertAfter("We're now on page 2. Here's my chart:");
            wrdRng.InsertParagraphAfter();

//.........这里部分代码省略.........
开发者ID:ViniciusConsultor,项目名称:controlhoras,代码行数:101,代码来源:Form1.cs

示例2: dd

    private void dd()
    {
        object objMiss = System.Reflection.Missing.Value;
        object objEndOfDocFlag = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
        //Start Word and create a new document.
        Word._Application oWord;
        Word._Document doc;
        oWord = new Word.Application();
        oWord.Visible = true;
        doc = oWord.Documents.Add(ref objMiss, ref objMiss, ref objMiss, ref objMiss);

        //Insert a paragraph at the end of the document.
        Word.Paragraph objPara2; //define paragraph object
        object oRng = doc.Bookmarks.get_Item(ref objEndOfDocFlag).Range; //go to end of the page
        objPara2 = doc.Content.Paragraphs.Add(ref oRng); //add paragraph at end of document
        objPara2.Range.Text = "Test Table Caption"; //add some text in paragraph
        objPara2.Format.SpaceAfter = 10; //define some style
        objPara2.Range.InsertParagraphAfter(); //insert paragraph

        //Insert a 2 x 2 table, (table with 2 row and 2 column)
        Word.Table Table; //create table object
        Word.Range range = doc.Bookmarks.get_Item(ref objEndOfDocFlag).Range; //go to end of document
        Table = doc.Tables.Add(range, 2, 2, ref objMiss, ref objMiss); //add table object in word document
        Table.Range.ParagraphFormat.SpaceAfter = 6;
        int iRow, iCols;
        string strText;
        for (iRow = 1; iRow <= 2; iRow++)
            for (iCols = 1; iCols <= 2; iCols++)
            {
                strText = "row:" + iRow + "col:" + iCols;
                Table.Cell(iRow, iCols).Range.Text = strText; //add some text to cell
            }
        Table.Rows[1].Range.Font.Bold = 1; //make first row of table BOLD
        Table.Columns[1].Width = oWord.InchesToPoints(3); //increase first column width

        //Add some text after table
        range = doc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
        range.InsertParagraphAfter(); //put enter in document
        range.InsertAfter("THIS IS THE SIMPLE WORD DEMO : THANKS YOU.");
        object szPath = "test.docx";
        doc.SaveAs(ref szPath);
    }
开发者ID:njmube,项目名称:ErpBapSoftNet_Producion,代码行数:42,代码来源:Frm_proforma_pedido.aspx.cs

示例3: AutomateWordImpl

        private static void AutomateWordImpl()
        {
            object missing = Type.Missing;
            object oEndOfDoc = @"\endofdoc";    // 预先定义的书签
            object notTrue = false;

            try
            {
                // 创建一个Microsoft Word实例并令其不可见

                Word.Application oWord = new Word.Application();
                oWord.Visible = false;
                Console.WriteLine("Word.Application is started");

                // 创建一个新的文档

                Word.Document oDoc = oWord.Documents.Add(ref missing, ref missing,
                    ref missing, ref missing);

                // 插入段落

                Console.WriteLine("Insert a paragraph");

                Word.Paragraph oPara = oDoc.Paragraphs.Add(ref missing);
                oPara.Range.Text = "Heading 1";
                oPara.Range.Font.Bold = 1;
                oPara.Range.InsertParagraphAfter();

                // 插入表格

                Console.WriteLine("Insert a table");

                Word.Range oBookmarkRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                Word.Table oTable = oDoc.Tables.Add(oBookmarkRng, 5, 2,
                    ref missing, ref missing);
                oTable.Range.ParagraphFormat.SpaceAfter = 6;
                for (int r = 1; r <= 5; r++)
                {
                    for (int c = 1; c <= 2; c++)
                    {
                        oTable.Cell(r, c).Range.Text = "r" + r + "c" + c;
                    }
                }

                // 改变列1和列2的宽度
                oTable.Columns[1].Width = oWord.InchesToPoints(2);
                oTable.Columns[2].Width = oWord.InchesToPoints(3);

                // 将文档保存为.docx文件并关闭

                Console.WriteLine("Save and close the document");

                object fileName = Path.GetDirectoryName(
                    Assembly.GetExecutingAssembly().Location) + "\\Sample2.docx";
                object fileFormat = Word.WdSaveFormat.wdFormatXMLDocument;
                oDoc.SaveAs(ref fileName, ref fileFormat, ref missing,
                    ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref missing, ref missing, ref missing,
                    ref missing);
                ((Word._Document)oDoc).Close(ref missing, ref missing,
                    ref missing);

                // 退出Word应用程序

                Console.WriteLine("Quit the Word application");
                ((Word._Application)oWord).Quit(ref notTrue, ref missing,
                    ref missing);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Solution2.AutomateWord throws the error: {0}",
                       ex.Message);
            }
        }
开发者ID:zealoussnow,项目名称:OneCode,代码行数:75,代码来源:Solution2.cs


注:本文中的Microsoft.Office.Interop.Word.Application.InchesToPoints方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。