• 黄聪: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;
                }
            }

  • 相关阅读:
    模糊查询的like '%$name$%'的sql注入避免
    在VS2010中使用Git(转)
    android WebView解析 调用html5
    git
    推荐!手把手教你使用Git
    羽毛拍十大品牌
    乒乓球拍板和皮子世界排名
    足球小记
    centos 网络启动 在/etc/sysconfig/network-scripts/ifcfg-eth1onboot=yes即可
    MyEclipseGen--------生成
  • 原文地址:https://www.cnblogs.com/huangcong/p/1697048.html
Copyright © 2020-2023  润新知