淺析C#編程實現動態生成Word文檔(2)_.Net教程
推薦:淺析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的研究。 最近
- asp.net如何得到GRIDVIEW中某行某列值的方法
- .net SMTP發送Email實例(可帶附件)
- js實現廣告漂浮效果的小例子
- asp.net Repeater 數據綁定的具體實現
- Asp.Net 無刷新文件上傳并顯示進度條的實現方法及思路
- Asp.net獲取客戶端IP常見代碼存在的偽造IP問題探討
- VS2010 水晶報表的使用方法
- ASP.NET中操作SQL數據庫(連接字符串的配置及獲取)
- asp.net頁面傳值測試實例代碼
- DataGridView - DataGridViewCheckBoxCell的使用介紹
- asp.net中javascript的引用(直接引入和間接引入)
- 三層+存儲過程實現分頁示例代碼
- 相關鏈接:
- 教程說明:
.Net教程-淺析C#編程實現動態生成Word文檔(2)。