黄聪

论SEO对人类的重要性,请看我的博客:hcsem.com

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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;
            }
        }

posted on 2010-03-26 15:22  黄聪  阅读(440)  评论(0编辑  收藏  举报