Example #1
0
        /// <summary>
        /// 获取一个Cell
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public void Cell(int row, int column, dynamic input)
        {
            string rangStr    = ExcelUtilityMethod.ConvertToTitle(column + 1) + (row + 1).ToString();
            object tenmpRange = ExcelUtilityMethod.GetProperty(m_workSheet, "Range",
                                                               new object[] { rangStr });

            ExcelUtilityMethod.SetProperty(tenmpRange, "Value", new object[] { input });
        }
Example #2
0
        /// <summary>
        /// 添加Chart
        /// </summary>
        /// <returns></returns>
        public Chart AddChart()
        {
            Microsoft.Office.Interop.Excel.XlChartType use_ChartType =
                Microsoft.Office.Interop.Excel.XlChartType.xlColumnClustered;
            Microsoft.Office.Interop.Excel.XlChartLocation use_XlLocation =
                Microsoft.Office.Interop.Excel.XlChartLocation.xlLocationAutomatic;
            object chartsObject     = ExcelUtilityMethod.GetProperty(m_workBook, "Charts");
            object addedChartObject = ExcelUtilityMethod.UseMethod(chartsObject, "Add",
                                                                   new object[] { Type.Missing, Type.Missing, 1 });

            //图表形式
            ExcelUtilityMethod.SetProperty(addedChartObject, "ChartType", new object[] { use_ChartType });
            //图表位置
            ExcelUtilityMethod.UseMethod(addedChartObject, "Location", new object[] { use_XlLocation });
            return(new Chart(addedChartObject));
        }
Example #3
0
        /// <summary>
        /// 应用程序
        /// </summary>
        /// <exception cref="ArgumentException">没有安装Excel时抛出</exception>
        public Application()
        {
            try
            {
                latApplication = Activator.CreateInstance(Type.GetTypeFromProgID("Excel.Application"));
                //获取Excel App的句柄
                hwnd = new IntPtr(this.Hwnd);
                //通过Windows API获取Excel进程ID
                GetWindowThreadProcessId(hwnd, out pid);
            }
            catch
            {
                throw new ArgumentException("没有安装Microsoft Office Excel。");
            }

            //属性名
            string[] propertyNames =
                new string[] { "DisplayAlerts", "AlertBeforeOverwriting"
                               , "Visible", "Interactive", "UserControl", "AskToUpdateLinks",
                               "AutoFormatAsYouTypeReplaceHyperlinks", "DisplayClipboardWindow"
                               , "DisplayDocumentActionTaskPane", "DisplayDocumentInformationPanel"
                               , "DisplayExcel4Menus", "EnableCheckFileExtensions", "EnableLargeOperationAlert"
                               , "MergeInstances", "MouseAvailable", "ScreenUpdating" };

            foreach (var propertyName in propertyNames)
            {
                try
                {
                    ExcelUtilityMethod.SetProperty(latApplication, propertyName, new object[] { false });
                }
                catch (Exception) // 当设置属性出现异常时
                {
                    continue;     //跳过
                }
            }
        }
Example #4
0
 /// <summary>
 /// 批量输入数据
 /// </summary>
 /// <param name="input"></param>
 public void SetValue2(object[,] input)
 {
     ExcelUtilityMethod.SetProperty(m_range, "Value2", new object[] { input });
 }