當前位置:才華齋>計算機>office辦公>

在word文件中建立表格的方法詳解

office辦公 閱讀(8.14K)
  在Word文件中建立表格的方法詳解

複製程式碼 程式碼如下:

在word文件中建立表格的方法詳解

public string CreateWordFile()

{

string message = "";

try

{

Object Nothing = e;

string name = "";

object filename = @"C:Usersxiehuanxxx" + name; //檔案儲存路徑

//建立Word文件

ication WordApp = new icationClass();

ment WordDoc = (ref Nothing, ref Nothing, ref Nothing, ref Nothing);

//新增頁首

= tlineView;

View = ekPrimaryHeader;

rtAfter("[頁首內容]");

nment = ignParagraphRight;//設定右對齊

View = ekMainDocument;//跳出頁首設定

Spacing = 15f;//設定文件的行間距

//移動焦點並換行

object count = 14;

object WdLine = ne;//換一行;

Down(ref WdLine, ref count, ref Nothing);//移動焦點

Paragraph();//插入段落

//文件中建立表格

e newTable = (e, 12, 3, ref Nothing, ref Nothing);

//設定表格樣式

ideLineStyle = neStyleThickThinLargeGap;

deLineStyle = neStyleSingle;

mns[1]h = 100f;

mns[2]h = 220f;

mns[3]h = 105f;

//填充表格內容

(1, 1) = "產品詳細資訊表";

(1, 1) = 2;//設定單元格中字型為粗體

//合併單元格

(1, 1)e((1, 3));

icalAlignment = llAlignVerticalCenter;//垂直居中

nment = ignParagraphCenter;//水平居中

//填充表格內容

(2, 1) = "產品基本資訊";

(2, 1)r = lorDarkBlue;//設定單元格內字型顏色

//合併單元格

(2, 1)e((2, 3));

icalAlignment = llAlignVerticalCenter;

//填充表格內容

(3, 1) = "品牌名稱:";

(3, 2) = "BrandName";

//縱向合併單元格

(3, 3)ct();//選中一行

object moveUnit = ne;

object moveCount = 5;

object moveExtend = tend;

Down(ref moveUnit, ref moveCount, ref moveExtend);

e();

//插入圖片

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

object LinkToFile = false;

object SaveWithDocument = true;

object Anchor = e;

icture(FileName, ref LinkToFile, ref SaveWithDocument, ref Anchor);

neShapes[1]h = 100f;//圖片寬度

neShapes[1]ht = 100f;//圖片高度

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

e s = neShapes[1]ertToShape();

= apSquare;

(12, 1) = "產品特殊屬性";

(12, 1)e((12, 3));

//在表格中增加行

es[1](ref Nothing);

= "文件建立時間:" + ring();//“落款”

nment = ignParagraphRight;

//檔案儲存

As(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);

e(ref Nothing, ref Nothing, ref Nothing);

(ref Nothing, ref Nothing, ref Nothing);

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

}

catch (ption e)

{

(age);

}

return message;

}