久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

c#實現(xiàn)word創(chuàng)建表格合并單元格操作功能

 唐伯龍 2011-07-29

c#實現(xiàn)word創(chuàng)建表格合并單元格操作功能

減小字體 增大字體 作者:Hd資源網(wǎng)  來源:本站整理  發(fā)布時間:2010-04-19 10:43:55

word操作,包括打開word文檔,,創(chuàng)建表格,,合并單元格,保存退出

    WordOperator

    using System;
    using System.Web;
    using Microsoft.Office.Interop.Word;

    namespace CustomFileAccess
    {
        public class WordOperator
        {
            public void CreateWord()
            {
                Microsoft.Office.Interop.Word.Application wordApp = new Application();
                Microsoft.Office.Interop.Word.Document wordDocument = new Document();
                Microsoft.Office.Interop.Word.Table wordTable;
                Microsoft.Office.Interop.Word.Table wordTableCopy;

                object myNull = System.Reflection.Missing.Value;

                object strPath = HttpContext.Current.Server.MapPath(@"WordTemplete\MyWordTemplete.doc");
                object styleName = "Table Grid 8";

                try
                {
                    wordDocument = wordApp.Documents.Open(ref strPath, ref myNull, ref myNull, ref myNull,
                        ref myNull, ref myNull, ref myNull, ref myNull, ref myNull, ref myNull, ref myNull, ref myNull,
                        ref myNull, ref myNull, ref myNull, ref myNull);

                    object start = 0;
                    object end = 0;

                    Microsoft.Office.Interop.Word.Range wordRange = wordDocument.Range(ref start, ref end);

                    wordTable = wordDocument.Tables.Add(wordRange, 3, 13, ref myNull, ref myNull);

                    wordTable.Borders.OutsideColor = WdColor.wdColorAutomatic;
                    wordTable.Borders.OutsideColorIndex = WdColorIndex.wdAuto;
                    wordTable.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle;
                    wordTable.Borders.OutsideLineWidth = WdLineWidth.wdLineWidth050pt;

                    wordTable.Borders.InsideColor = WdColor.wdColorAutomatic;
                    wordTable.Borders.InsideColorIndex = WdColorIndex.wdAuto;
                    wordTable.Borders.InsideLineStyle = WdLineStyle.wdLineStyleSingle;
                    wordTable.Borders.InsideLineWidth = WdLineWidth.wdLineWidth050pt;

                    wordDocument.Tables[1].Cell(1, 1).Merge(wordDocument.Tables[1].Cell(2, 1));

                    wordDocument.Tables[1].Cell(1, 1).Range.Text = "cell 1, 1";
                    wordDocument.Tables[1].Cell(2, 2).Range.Text = "cell 2, 2";

                    wordDocument.Tables[1].Select();
                    wordApp.Selection.Copy();

                    wordDocument.Tables[1].Cell(1, 2).Range.Text = "The First Table";


                    object myunit = Microsoft.Office.Interop.Word.WdUnits.wdStory;
                    wordApp.Selection.EndKey(ref myunit, ref myNull);

                    wordApp.Selection.TypeParagraph();

                    wordApp.Selection.Paste();

                    wordDocument.Tables[2].Cell(1, 1).Range.Text = "The Second Table";

                    wordDocument.Save();
                }
                catch
                {
                    wordDocument.Close(ref myNull, ref myNull, ref myNull);
                    wordApp.Quit(ref myNull, ref myNull, ref myNull);
                    if (wordDocument != null)
                    {
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(wordDocument);
                        wordDocument = null;
                    }
                    if (wordApp != null)
                    {
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp);
                        wordApp = null;
                    }
                    GC.Collect();
                    throw new Exception("文檔生成失??!");

                }
                finally
                {
                    wordDocument.Close(ref myNull, ref myNull, ref myNull);
                    wordApp.Quit(ref myNull, ref myNull, ref myNull);
                }

            }
        }
    }

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,,不代表本站觀點,。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報,。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多