Beispiel #1
0
        /// <summary>
        /// 在指定位置上使用输入的二维数组插入图表
        /// </summary>
        /// <param name="type">插入的方式 (文件开始或文件结束位置)</param>
        /// <param name="value">二维数组</param>
        /// <param name="chartType">图表类型</param>
        /// <param name="rowHeader">行标题(null表示显示index值)</param>
        /// <param name="colHeader">列标题 (null表示显示Column1, Column2值)</param>
        public void InsertGraph(InsertionPoint type, double[,] value, WordChartStyle chartType = null, string[] rowHeader = null, string[] colHeader = null)
        {
            try
            {
                Word.Range     r = GetRange(type);
                dynamic        oShape;
                WordChartStyle style = chartType == null ? _chartStyle : chartType;
                if (_version > 12.0)
                {
                    oShape = _wordShapes.AddChart2(-1, (XlChartType)style.ChartStyle, r);
                }
                else
                {
                    oShape = _wordShapes.AddChart((XlChartType)style.ChartStyle, r);
                }

                //Demonstrate use of late bound oChart and oChartApp objects to
                //manipulate the chart object with MSGraph.
                Word.Chart oChart = oShape.Chart;

                //object oChartApp = oChart.Application;

                ArrayDataToGraphData(value, oChart, rowHeader, colHeader, style.FirstColumnAsXAxis);
            }
            catch (Exception ex)
            {
                ErrorParser(ex);
                return;
            }
        }
Beispiel #2
0
 /// <summary>
 /// 构造函式,使用模板
 /// </summary>
 /// <param name="template"></param>
 public WordReport(string template)
 {
     try
     {
         _defaultFont = new WordFont();
         _engine      = new Word.Application();
         _wordDoc     = _engine.Documents.Open(template, _missing, _missing, _missing, _missing, _missing, _missing, _missing, _missing, _missing, _missing, _missing, _missing, _missing, _missing, _missing);
         _wordTables  = _wordDoc.Tables;
         _wordShapes  = _wordDoc.InlineShapes;
         _version     = DetermineVersion();
         _chartStyle  = new WordChartStyle();
     }
     catch (Exception ex)
     {
         ErrorParser(ex);
         return;
     }
 }