|
c#操作word表格(2) Object end = Type.Missing; Object unit = Type.Missing; Object count = Type.Missing; wordDoc.Range(ref start, ref end).Delete(ref unit, ref count);
object rng = Type.Missing; string strInfo = this.txtNameCh.Text.ToString()+"明细表"+strSign+"\r\n"; start = 0; end = 0; wordDoc.Range(ref start, ref end).InsertBefore(strInfo); wordDoc.Range(ref start, ref end).Font.Name = "Verdana"; wordDoc.Range(ref start, ref end).Font.Size = 20; wordDoc.Range(ref start, ref end).ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
start = 8; end = strInfo.Length; wordDoc.Range(ref start, ref end).InsertParagraphAfter();//插入回车
if(DT.Rows.Count>0) { //存在数据项 //添加一个表格 object missingValue = Type.Missing; object location = strInfo.Length; //注:若location超过已有字符的长度将会出错。一定要比"明细表"串多一个字符 Word.Range rng2 = wordDoc.Range(ref location, ref location);
wordDoc.Tables.Add(rng2, 13, 6, ref missingValue, ref missingValue); wordDoc.Tables.Item(1).Rows.HeightRule = Word.WdRowHeightRule.wdRowHeightAtLeast; wordDoc.Tables.Item(1).Rows.Height = wordApp.CentimetersToPoints(float.Parse("0.8")); wordDoc.Tables.Item(1).Range.Font.Size = 10; wordDoc.Tables.Item(1).Range.Font.Name = "宋体"; wordDoc.Tables.Item(1).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter; wordDoc.Tables.Item(1).Range.Cells.VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
|