110,534
社区成员
发帖
与我相关
我的任务
分享
object oFileName = @"C:\Users\admin\Desktop\test - 副本.docx";
object oReadOnly = false;
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word._Application oWord;
Microsoft.Office.Interop.Word._Document oDoc;
oWord = m_word;
oWord.Visible = false;
oDoc = oWord.Documents.Open(ref oFileName, ref oMissing, ref oReadOnly, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
//MessageBox.Show(oDoc.Tables.Count.ToString());
for (int tablePos = 1; tablePos <= oDoc.Tables.Count; tablePos++)
{
Microsoft.Office.Interop.Word.Table nowTable = oDoc.Tables[tablePos];
//调整边框为双线
nowTable.Borders.OutsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;
//调整内框为单线
nowTable.Borders.InsideLineStyle = MSWord.WdLineStyle.wdLineStyleDouble;
//调整字号及字体
nowTable.Range.Font.Name = "宋体";
nowTable.Range.Font.Size = 10.5F;
//调整行距
nowTable.Range.ParagraphFormat.LineSpacingRule = MSWord.WdLineSpacing.wdLineSpaceSingle;
//调整缩进
nowTable.Range.ParagraphFormat.LeftIndent = 0;
nowTable.Range.ParagraphFormat.RightIndent = 0;
nowTable.Range.ParagraphFormat.FirstLineIndent = 0;
nowTable.Range.ParagraphFormat.CharacterUnitFirstLineIndent = 0;
//调整段前段后间距--第一种尝试
nowTable.Range.ParagraphFormat.SpaceBeforeAuto = 0;// float.Parse("0");
nowTable.Range.ParagraphFormat.SpaceBefore = 100;
nowTable.Range.ParagraphFormat.SpaceAfterAuto = 0;
nowTable.Range.ParagraphFormat.SpaceAfter = 130;// float.Parse("0");
//第二种尝试
nowTable.Range.Paragraphs.SpaceBeforeAuto = 0;// float.Parse("0");
nowTable.Range.Paragraphs.SpaceBefore = 100;
nowTable.Range.Paragraphs.SpaceAfterAuto = 0;
nowTable.Range.Paragraphs.SpaceAfter = 130;// float.Parse("0");
}