淺析C#編程實現動態生成Word文檔(2)_.Net教程

      編輯Tag賺U幣
      教程Tag:暫無Tag,歡迎添加,賺取U幣!

      推薦:淺析Asp.net2.0之自定義控件ImageButton
      前言 上個星期三開始學自定義控件,做了不少練習。花了一上午時間寫了一個imageButton,以前就像寫這個控件,只是不會。 圖片 正文 這個控件模仿winform中的button,可以支持圖片和文字。可以選擇執行服務器端程序還是客戶端程序,還有一些簡單的設置。 不足

       

         // 填充表格內容

          newTable.Cell( 2 ,  1 ).Range.Text  =   " 產品基本信息 " ;

          newTable.Cell( 2 ,  1 ).Range.Font.Color  =  Word.WdColor.wdColorDarkBlue; // 設置單元格內字體顏色

          // 合并單元格

          newTable.Cell( 2 ,  1 ).Merge(newTable.Cell( 2 ,  3 ));

          WordApp.Selection.Cells.VerticalAlignment  =  Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;

          // 填充表格內容

          newTable.Cell( 3 ,  1 ).Range.Text  =   " 品牌名稱: " ;

          newTable.Cell( 3 ,  2 ).Range.Text  =  BrandName;

          // 縱向合并單元格

          newTable.Cell( 3 ,  3 ).Select(); // 選中一行

          object  moveUnit  =  Word.WdUnits.wdLine;

          object  moveCount  =   5 ;

          object  moveExtend  =  Word.WdMovementType.wdExtend;

          WordApp.Selection.MoveDown( ref  moveUnit,  ref  moveCount,  ref  moveExtend);

          WordApp.Selection.Cells.Merge();

          // 插入圖片

          string  FileName  =  Picture; // 圖片所在路徑

          object  LinkToFile  =   false ;

          object  SaveWithDocument  =   true ;

          object  Anchor  =  WordDoc.Application.Selection.Range;

          WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(FileName,  ref  LinkToFile,  ref  SaveWithDocument,  ref  Anchor);

          WordDoc.Application.ActiveDocument.InlineShapes[ 1 ].Width  =  100f; // 圖片寬度

          WordDoc.Application.ActiveDocument.InlineShapes[ 1 ].Height  =  100f; // 圖片高度

          // 將圖片設置為四周環繞型

          Word.Shape s  =  WordDoc.Application.ActiveDocument.InlineShapes[ 1 ].ConvertToShape();

          s.WrapFormat.Type  =  Word.WdWrapType.wdWrapSquare;

          newTable.Cell( 12 ,  1 ).Range.Text  =   " 產品特殊屬性 " ;

          newTable.Cell( 12 ,  1 ).Merge(newTable.Cell( 12 ,  3 ));

          // 在表格中增加行

          WordDoc.Content.Tables[ 1 ].Rows.Add( ref  Nothing);

          WordDoc.Paragraphs.Last.Range.Text  =   " 文檔創建時間: "   +  DateTime.Now.ToString(); // “落款”

          WordDoc.Paragraphs.Last.Alignment  =  Word.WdParagraphAlignment.wdAlignParagraphRight;

          // 文件保存

          WordDoc.SaveAs( ref  filename,  ref  Nothing,  ref  Nothing,  ref  Nothing,  ref  Nothing,  ref  Nothing,  ref  Nothing,  ref  Nothing,  ref  Nothing,  ref  Nothing,  ref  Nothing,  ref  Nothing,  ref  Nothing,  ref  Nothing,  ref  Nothing,  ref  Nothing);

          WordDoc.Close( ref  Nothing,  ref  Nothing,  ref  Nothing);

          WordApp.Quit( ref  Nothing,  ref  Nothing,  ref  Nothing);

          message = name + " 文檔生成成功,以保存到C:CNSI下 " ;

          }

          catch

          ... {

          message  =   " 文件導出異常! " ;

          }

          return  message;

          }

       

      分享:淺談.net程序員,該不該學IL?
      最近一直在思考一個問題,那就是.net程序員的發展,應該往上走還是往下走的事情。所謂往上走,我的理解是朝著系統架構方向發展,從原來的編碼工作轉向架構、設計、分析等等工作。 而往下走,是研究.net底層原理和實現,可能大部分就是對IL和CLR的研究。 最近

      共2頁上一頁12下一頁
      來源:模板無憂//所屬分類:.Net教程/更新時間:2009-10-04
      相關.Net教程