ASP .Net C# 下 Word開發資料

來源:互聯網
上載者:User

Saving Word Doc back to Web Server
http://www.theimagingsourceforums.com/showthread.php?t=317081

 

 http://support.microsoft.com/kb/257757/ 伺服器端 Office 自動化注意事項
http://msdn.microsoft.com/msdnmag/issues/06/11/BasicInstincts/default.aspx?loc=zh 
 
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1174465&SiteID=1 
 
http://blog.joycode.com/kaneboy/archive/2004/11/03/37889.aspx
http://blog.csdn.net/whchen/archive/2006/12/15/1444177.aspx
http://msdn.microsoft.com/msdnmag/issues/06/11/BasicInstincts/default.aspx?loc=zh在伺服器端產生 Word 2007 文檔

搜尋 DSO Framer
找不到
Word Object Library 11.0 重新安裝VS 2005
在B/S中用DSO Framer OCX + Excel 解決複雜的報表問題
http://www.cnblogs.com/Dragonpro/archive/2006/12/01/228144.html

Developing Word Application using C# & DSO Framer
http://bbs.hidotnet.com/712/ShowPost.aspx
將Excel嵌入你的.Net程式2-使用dsoFramer

http://caidehui.cnblogs.com/archive/2006/04/19/378782.html

在Web頁面上直接開啟、編輯、建立Office文檔  終於找到了
http://blog.joycode.com/kaneboy/archive/2004/11/03/37889.aspx

SAMPLE: FramerEx.exe 是 MDI ActiveX 文檔容器樣本用 VisualC++ 編寫
http://support.microsoft.com/kb/268470/
Visual C++ ActiveX Control for hosting Office documents in Visual Basic or HTML
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q311/7/65.asp&NoWebContent=1#

 用iframe  
  <iframe   name="fraRead"   frameborder="0"   height="300"   width="500"   scrolling="auto"   src="1.doc"></iframe>

 

C#操作Word文檔(Office 2007)http://www.cnsdn.com.cn/blog/article.asp?id=1791

asp.net  Word 操作 (比較全面)
http://blog.csdn.net/c_g1113/archive/2006/11/16/1388715.aspx

從ASP.NET得到Microsoft Word文檔
http://supersand.cnblogs.com/archive/2005/11/09/272152.html

C#中如何儲存文本為Word檔案或Excel檔案
http://www.cnblogs.com/phinecos/archive/2006/12/14/592635.html
用.net操作word
http://www.studycs.com/ShowArticle.aspx?id=9

Office Com AddIn 開發心得
http://mancini.cnblogs.com/archive/2005/03/28/120398.aspx

wp=new CCWordApp();
wp.OpenWithTemplate(Page.MapPath(“模版.doc“));
wp.InsertText(“aa“);
wp.GoToRightCharacter(14);
wp.InsertText(“bb“);
wp.GoToRightCell();
wp.GoToRightCell();
wp.InsertText(“cc“);
... 其餘參閱CCWordApp類。

最上面漏了CCWordApp wp=null;
以下是CCWordApp類:
///
/// CCWordApp 的摘要說明。
///
public class CCWordApp
{
        private Word.ApplicationClass oWordApplic;// a reference to Word application
        private Word.Document oDoc;// a reference to the document
        private object missing = System.Reflection.Missing.Value;
        public CCWordApp() {
            //
            // TODO: 在此處添加建構函式邏輯
            //
            oWordApplic = new Word.ApplicationClass();
        }
        // Open a file (the file must exists) and activate it
        public void Open( string strFileName)
        {
            object fileName = strFileName;
            object readOnly = false;
            object isVisible = true;
            oDoc = oWordApplic.Documents.Open(ref fileName, ref missing,ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible,ref missing,ref missing,ref missing,ref missing);
            oDoc.Activate();
        }
        //Open a new with template
        public void OpenWithTemplate(string strFileName) {
            object fileName = strFileName;
            oDoc = oWordApplic.Documents.Add(ref fileName, ref missing,ref missing, ref missing);
            oDoc.Activate();
        }
        // Open a new document
        public void Open( )
        {
            oDoc = oWordApplic.Documents.Add(ref missing, ref missing,ref missing, ref missing);
            oDoc.Activate();
        }
        public void Quit( )
        {
            oDoc.Close(ref missing,ref missing,ref missing);
            oWordApplic.Quit(ref missing, ref missing, ref missing);
        }
        public void Save( )
        {
            oDoc.Save();
        }
        public void SaveAs(string strFileName )
        {
            object fileName = strFileName;
            oDoc.SaveAs(ref fileName, 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, ref missing);
        }
        // Save the document in HTML format
        public void SaveAsHtml(string strFileName )
        {
            object fileName = strFileName;
            object Format = (int)Word.WdSaveFormat.wdFormatHTML;
            oDoc.SaveAs(ref fileName, ref Format,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);
        }
        public void InsertText( string strText)
        {
            oWordApplic.Selection.TypeText(strText);
        }
        public void InsertLineBreak( )
        {
            oWordApplic.Selection.TypeParagraph();
        }
        public void InsertLineBreak( int nline)
        {
            //for (int i=0; i -------------------------------------------------------------------------------
        }

        public void InsertBookMark(string BookMark)
        {
            /* VB : With ActiveDocument.Bookmarks .Add
             * Range:=Selection.Range,
             * Name:="dq"
             * .DefaultSorting = wdSortByName
             * .ShowHidden = False End With
             */
            object Range=oWordApplic.Selection.Range;
            oWordApplic.ActiveDocument.Bookmarks.Add(BookMark,ref Range);
        }
    public void InsertPicture(string FileName)
    {
        /* VB : Selection.InlineShapes.AddPicture
         * FileName:=zp,
         * LinkToFile:=False,
         * SaveWithDocument:=True
         */
        object LinkToFile=false;
        object SaveWithDocument=true;
        oWordApplic.Selection.InlineShapes.AddPicture(FileName,ref LinkToFile,ref SaveWithDocument,ref missing);
    }
    // Go to a predefined bookmark, if the bookmark doesn’t exists the application will raise an error
    public void GotoBookMark( string strBookMarkName)
    {
        // VB : Selection.GoTo What:=wdGoToBookmark, Name:="nome"
        object Bookmark = (int)Word.WdGoToItem.wdGoToBookmark;
        object NameBookMark = strBookMarkName;
        oWordApplic.Selection.GoTo(ref Bookmark, ref missing, ref missing,ref NameBookMark);
    }
    public void GoToTheEnd( )
    {
        // VB : Selection.EndKey Unit:=wdStory
        object unit ; unit = Word.WdUnits.wdStory ;
        oWordApplic.Selection.EndKey ( ref unit, ref missing);
    }
    public void GoToTheBeginning( ) {
        // VB : Selection.HomeKey Unit:=wdStory object unit ;
        unit = Word.WdUnits.wdStory ;
        oWordApplic.Selection.HomeKey ( ref unit, ref missing);
    }
    public void GoToTheTable(int ntable )
    {
        //Selection.GoTo What:=wdGoToTable, Which:=wdGoToFirst, Count:=1, Name:=""
        // Selection.Find.ClearFormatting
        // With Selection.Find
        // .Text = ""
        // .Replacement.Text = ""
        // .Forward = True
        // .Wrap = wdFindContinue
        // .Format = False
        // .MatchCase = False
        // .MatchWholeWord = False
        // .MatchWildcards = False
        // .MatchSoundsLike = False
        // .MatchAllWordForms = False
        // End With
        object what; what = Word.WdUnits.wdTable ;
        object which; which = Word.WdGoToDirection.wdGoToFirst;
        object count;
        count = 1 ;
        oWordApplic.Selection.GoTo( ref what, ref which, ref count, ref missing);
        oWordApplic.Selection.Find.ClearFormatting(); oWordApplic.Selection.Text = "";
    }
    public void GoToRightCharacter( int Count)
    {
        // Selection.MoveRight Unit:=wdCharacter
        object count=Count;
        object direction;
        direction = Word.WdUnits.wdCharacter;
        oWordApplic.Selection.MoveRight(ref direction,ref count,ref missing);
    }
    public void GoToRightCharacterAndSelected( int Count,string Extend)
    {
        // Selection.MoveDown Unit:=wdLine, Count:=32, Extend:=wdExtend
        object count=Count;
        object extend=Extend;
        object direction;
        direction = Word.WdUnits.wdLine;
        oWordApplic.Selection.MoveRight(ref direction,ref count,ref extend);
    }
    public void CopyNewTable()
    {
        /*VB: Selection.WholeStory Selection.Copy*/
        //object Extend=Word.WdMovementType.wdExtend;
        //object direction = Word.WdUnits.wdLine;
        //oWordApplic.Selection.MoveDown(ref direction,ref count,ref Extend);
        oWordApplic.Selection.WholeStory();
        oWordApplic.Selection.Copy();
        GoToTheBeginning();
    }
    public void GoToRightCell( )
    {
        // Selection.MoveRight Unit:=wdCell
        object direction;
        direction = Word.WdUnits.wdCell;
        oWordApplic.Selection.MoveRight(ref direction,ref missing,ref missing);
    } public void GoToLeftCell( )
    {
        // Selection.MoveRight Unit:=wdCell
        object direction;
        direction = Word.WdUnits.wdCell;
        oWordApplic.Selection.MoveLeft(ref direction,ref missing,ref missing);
    }
    public void GoToDownCell( )
    {
        // Selection.MoveRight Unit:=wdCell
        object direction;
        direction = Word.WdUnits.wdLine;
        oWordApplic.Selection.MoveDown(ref direction,ref missing,ref missing);
    }
    public void GoToUpCell( )
    {
        // Selection.MoveRight Unit:=wdCell
        object direction;
        direction = Word.WdUnits.wdLine;
        oWordApplic.Selection.MoveUp(ref direction,ref missing,ref missing);
    }
    public void GoToUpCell(int Count )
    {
        // Selection.MoveRight Unit:=wdCell
        object count=Count;
        object direction;
        direction = Word.WdUnits.wdLine;
        oWordApplic.Selection.MoveUp(ref direction,ref count,ref missing);
    }
    // this function doesn’t work
    public void InsertPageNumber( string strType, bool bHeader )
    {
        object alignment ;
        object bFirstPage = false;
        object bF = true;
        //if (bHeader == true)
        //WordApplic.Selection.HeaderFooter.PageNumbers.ShowFirstPageNumber = bF;
        switch (strType)
        {
            case "Center":
                alignment = Word.WdPageNumberAlignment.wdAlignPageNumberCenter;
            //WordApplic.Selection.HeaderFooter.PageNumbers.Add(ref alignment,ref bFirstPage);
            //Word.Selection objSelection = WordApplic.pSelection;
            //oWordApplic.Selection.HeaderFooter.PageNumbers.Item(1).Alignment = Word.WdPageNumberAlignment.wdAlignPageNumberCenter;
                break;
            case "Right":
                alignment = Word.WdPageNumberAlignment.wdAlignPageNumberRight;
            //oWordApplic.Selection.HeaderFooter.PageNumbers.Item(1).Alignment = Word.WdPageNumberAlignment.wdAlignPageNumberRight;
                break;
            case "Left":
                alignment = Word.WdPageNumberAlignment.wdAlignPageNumberLeft;
                oWordApplic.Selection.HeaderFooter.PageNumbers.Add(ref alignment,ref bFirstPage);
                break;
        }
    }

}

把上面兩段合起來。至於其他的操作,可在word中先錄製宏,再轉成c#就行了。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.