109,883
社区成员




public bool ExportWord(DataSet ds, string saveFileName)
{
bool fileSaved = false;
object filename = saveFileName;
try
{
Object Nothing = System.Reflection.Missing.Value;
//创建Word文档
Word.Application WordApp = new Word.ApplicationClass();
Word.Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
//文档中创建表格
WordApp.Selection.TypeParagraph();
Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, 13, 5, ref Nothing, ref Nothing);
//设置表格样式
//newTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleThickThinLargeGap;
//newTable.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
newTable.Columns[1].Width = 100f;
newTable.Columns[2].Width = 100f;
newTable.Columns[3].Width = 100f;
newTable.Columns[4].Width = 50f;
newTable.Columns[5].Width = 50f;
//填充表格内容
newTable.Cell(1, 1).Range.Text = "登记表";
newTable.Cell(1, 1).Range.Bold = 3;//设置单元格中字体为粗体
//合并单元格
newTable.Cell(1, 1).Merge(newTable.Cell(1, 5));
WordApp.Selection.Cells.VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//垂直居中
WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中