zoukankan      html  css  js  c++  java
  • 黄聪:C#操作Word 插入文本

    public static bool InsertText(string strText, System.Drawing.Font font, Alignment alignment, bool isAftre, int startNum, int endNum)
            {
                try
                {
                    Word.Range rng = oDoc.Content;
                    object start = startNum;
                    object end = endNum;

                    rng = oDoc.Range(ref start, ref end);

                    if (isAftre == true)
                    {
                        strText += "\r\n";
                    }

                    rng.Text = strText;

                    rng.Font.Name = font.Name;
                    rng.Font.Size = font.Size;
                    if (font.Style == FontStyle.Bold) { rng.Font.Bold = 1; } //设置单元格中字体为粗体

                    if (alignment == Alignment.居中)
                    { rng.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; }
                    else if (alignment == Alignment.左对齐)
                    { rng.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; }
                    else if (alignment == Alignment.右对齐)
                    { rng.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight; }

                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }

  • 相关阅读:
    关于asp.netCore3.0区域和路由配置
    用Autofac替换.net core 内置容器
    C#Assembly详解
    MongoDB
    Python
    Python,正则表达式
    Python
    Python
    Gevent和猴子补丁
    Django
  • 原文地址:https://www.cnblogs.com/huangcong/p/1697048.html
Copyright © 2011-2022 走看看