C# MSGraph.Chart.8 画图,制表

本文档展示了如何使用C#结合MSGraph库在Word文档中创建表格和图表。通过`Query`方法获取数据,然后利用`Tables.Add`方法插入表格,设置表格样式,并填充内容。接着创建图表,设定图表类型、颜色、标签等属性,以及调整X轴的刻度显示方向。
摘要由CSDN通过智能技术生成

using System;
using System.Data;
using System.Data.Common;
using System.Data.OleDb;
using System.IO;
using System.Windows.Forms;
using Graph = Microsoft.Office.Interop.Graph;
using Word = Microsoft.Office.Interop.Word;

 

namespace WeeklyReporter
{
    public partial class MainForm : Form
    { 

        private void CreateReport(DateTime fromDate, DateTime toDate, string reportDepartment)
        {  

                DateTable dt = Query("...");

                if (oDoc.Bookmarks.Exists(Convert.ToString(oBookMark)))
                {
                    object nothing = System.Reflection.Missing.Value;

                    //文档中创建表格
                    Microsoft.Office.Interop.Word.Table gmsTable = oDoc.Tables.Add(oDoc.Bookmarks[oBookMark].Range, dt.Rows.Count + 1, dt.Columns.Count, ref nothing, ref nothing);

                    //设置表格样式
                    gmsTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
                    gmsTable.Borders.OutsideColor = Word.WdColor.wdColorPaleBlue;
                    gmsTable.Borders.OutsideLineWidth = Word.WdLineWidth.wdLineWidth225pt;

                    gmsTable.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
                    gmsTable.Borders.InsideColor = Word.WdColor.wdColorPaleBlue;
                    gmsTable.Borders.InsideLineWidth = Word.WdLineWidth.wdLineWidth225pt;

                    //填充表格内容
                    for (int i = 0; i < dt.Columns.Count; i++)
                    {
                        gmsTable.Cell(1, i + 1).Shading.ForegroundPatternColor = Word.WdColor.wdColorLightGreen;
                        gmsTable.Cell(1, i + 1).Range.Bold = 20;
                    }

                    gmsTable.Cell(1, 1).Range.Text = "A";
                    gmsTable.Cell(1, 2).Range.Text = "B";
                    gmsTable.Cell(1, 3).Range.Text = "C";
                    gm

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值