コード例 #1
0
        /// <summary>
        /// 获得终止行
        /// </summary>
        /// <returns></returns>
        public int EndRow()
        {
            object tempEnd = ExcelUtilityMethod.GetProperty(m_range, "End",
                                                            new object[] { Microsoft.Office.Interop.Excel.XlDirection.xlDown });

            return((int)ExcelUtilityMethod.GetProperty(tempEnd, "Row"));
        }
コード例 #2
0
        /// <summary>
        /// 自动调整
        /// </summary>
        public void AutoFit()
        {
            object temp = ExcelUtilityMethod.GetProperty(m_range, "EntireColumn");

            ExcelUtilityMethod.UseMethod(temp, "AutoFit", null);
            return;
        }
コード例 #3
0
ファイル: Chart.cs プロジェクト: Woody-Hu/ExcelLateBinding
 /// <summary>
 /// 为Chart设置数据源
 /// </summary>
 /// <param name="input"></param>
 public void SetSourceData(Range input)
 {
     Microsoft.Office.Interop.Excel.XlRowCol useType =
         Microsoft.Office.Interop.Excel.XlRowCol.xlColumns;
     ExcelUtilityMethod.UseMethod(m_chart, "SetSourceData",
                                  new object[] { input.ThisRangeObject, useType });
 }
コード例 #4
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 });
        }
コード例 #5
0
        /// <summary>
        /// 获取一个Cell
        /// </summary>
        /// <param name="row"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        public dynamic Cell(int row, int column)
        {
            string rangStr    = ExcelUtilityMethod.ConvertToTitle(column + 1) + (row + 1).ToString();
            object tenmpRange = ExcelUtilityMethod.GetProperty(m_workSheet, "Range",
                                                               new object[] { rangStr });

            return(ExcelUtilityMethod.GetProperty(tenmpRange, "Value"));
        }
コード例 #6
0
        /// <summary>
        /// 在此工作表添加一个图片
        /// </summary>
        /// <param name="strTempPath"></param>
        /// <param name="left"></param>
        /// <param name="top"></param>
        /// <param name="tempImageHeight"></param>
        /// <param name="tempImageWidth"></param>
        /// <returns></returns>
        public Shape AddPicture(string strTempPath, float left, float top, float tempImageHeight, float tempImageWidth)
        {
            object tempShapes = ExcelUtilityMethod.GetProperty(m_workSheet, "Shapes");
            object temp       = ExcelUtilityMethod.UseMethod(tempShapes, "AddPicture", new object[] { strTempPath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue,
                                                                                                      left, top, tempImageWidth, tempImageHeight });

            return(new Shape(temp));
        }
コード例 #7
0
        /// <summary>
        /// 获取一个Range
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public Range Range(int row, int column)
        {
            string rangStr    = ExcelUtilityMethod.ConvertToTitle(column + 1) + (row + 1).ToString();
            object tenmpRange = ExcelUtilityMethod.GetProperty(m_workSheet, "Range",
                                                               new object[] { rangStr });

            return(new Range(tenmpRange));
        }
コード例 #8
0
ファイル: Shape.cs プロジェクト: Woody-Hu/ExcelLateBinding
 /// <summary>
 /// 将图片拷贝到剪切板
 /// </summary>
 public void CopyPicture()
 {
     ExcelUtilityMethod.UseMethod(m_thisShape, "CopyPicture",
                                  new object[] {
         Microsoft.Office.Interop.Excel.XlPictureAppearance.xlScreen,
         Microsoft.Office.Interop.Excel.XlCopyPictureFormat.xlBitmap
     });
 }
コード例 #9
0
        /// <summary>
        /// 获取一个Range
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public Range Range(int rowOne, int columnOne, int rowTwo, int columnTwo)
        {
            string rangStrOne = ExcelUtilityMethod.ConvertToTitle(columnOne + 1) + (rowOne + 1).ToString();
            string rangStrTwo = ExcelUtilityMethod.ConvertToTitle(columnTwo + 1) + (rowTwo + 1).ToString();
            string rangStr    = rangStrOne + ":" + rangStrTwo;
            object tenmpRange = ExcelUtilityMethod.GetProperty(m_workSheet, "Range",
                                                               new object[] { rangStr });

            return(new Range(tenmpRange));
        }
コード例 #10
0
        /// <summary>
        /// 在此工作表添加一个图表
        /// </summary>
        /// <param name="left"></param>
        /// <param name="top"></param>
        /// <returns></returns>
        public Chart AddChart(double left = 0.0d, double top = 0.0d)
        {
            Microsoft.Office.Interop.Excel.XlChartType use_ChartType =
                Microsoft.Office.Interop.Excel.XlChartType.xlColumnClustered;
            object tempshapes = ExcelUtilityMethod.GetProperty(m_workSheet, "Shapes");

            object tempShape = ExcelUtilityMethod.UseMethod(tempshapes, "AddChart",
                                                            new object[] { use_ChartType, left, top });

            object tempChart = ExcelUtilityMethod.GetProperty(tempShape, "Chart");

            return(new Chart(tempChart));
        }
コード例 #11
0
 /// <summary>
 /// 退出
 /// </summary>
 public void Quit()
 {
     ExcelUtilityMethod.UseMethod(latApplication, "Quit", null);
     try
     {
         Process tempProcess = Process.GetProcessById(pid);
         tempProcess.Kill();
     }
     catch
     {
         ;
     }
 }
コード例 #12
0
ファイル: Workbook.cs プロジェクト: Woody-Hu/ExcelLateBinding
        /// <summary>
        /// 全名称
        /// </summary>
        /// <returns></returns>
        public string FullName()
        {
            object returnValue = ExcelUtilityMethod.UseMethod(m_workBook, "FullName", null);

            if (returnValue is string)
            {
                return((string)returnValue);
            }
            else //返回有误时(不是字符串格式)返回空字符串
            {
                return(string.Empty);
            }
        }
コード例 #13
0
ファイル: Workbook.cs プロジェクト: Woody-Hu/ExcelLateBinding
        /// <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));
        }
コード例 #14
0
        /// <summary>
        /// 打开一个文档
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public Workbook Open(string path)
        {
            object thisObject;

            try
            {
                thisObject = ExcelUtilityMethod.UseMethod(workbooks, "Open", new object[] { path, false, Missing.Value,
                                                                                            Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                                                                                            Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value });
            }
            catch (Exception)
            {
                thisObject = ExcelUtilityMethod.UseMethod(workbooks, "Open", new object[] { path, false });
            }


            return(new Workbook(thisObject));
        }
コード例 #15
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;     //跳过
                }
            }
        }
コード例 #16
0
ファイル: Chart.cs プロジェクト: Woody-Hu/ExcelLateBinding
 /// <summary>
 /// 设置图例
 /// </summary>
 public void ApplyDataLabels()
 {
     ExcelUtilityMethod.UseMethod(m_chart, "ApplyDataLabels", null);
 }
コード例 #17
0
 /// <summary>
 /// 关闭此文档
 /// </summary>
 public void Close()
 {
     ExcelUtilityMethod.UseMethod(workbooks, "Close", null);
 }
コード例 #18
0
        /// <summary>
        /// 获得其中一个工作表
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public Worksheet Get_Item(int index)
        {
            object thisObject = ExcelUtilityMethod.GetProperty(m_workSheets, "Item", new object[] { index });

            return(new Worksheet(thisObject));
        }
コード例 #19
0
 /// <summary>
 /// 获取一个Range
 /// </summary>
 /// <param name="input"></param>
 /// <returns></returns>
 public Range Range(string input)
 {
     return(new Range(ExcelUtilityMethod.GetProperty(m_workSheet, "Range", new object[] { input, Missing.Value })));
 }
コード例 #20
0
 /// <summary>
 /// 批量输入数据
 /// </summary>
 /// <param name="input"></param>
 public void SetValue2(object[,] input)
 {
     ExcelUtilityMethod.SetProperty(m_range, "Value2", new object[] { input });
 }
コード例 #21
0
ファイル: Workbook.cs プロジェクト: Woody-Hu/ExcelLateBinding
 /// <summary>
 /// 关闭工作簿
 /// </summary>
 public void Close()
 {
     ExcelUtilityMethod.UseMethod(m_workBook, "Close", new object[] { null, null, null });
 }
コード例 #22
0
ファイル: Workbook.cs プロジェクト: Woody-Hu/ExcelLateBinding
 /// <summary>
 /// 保存
 /// </summary>
 public void Save()
 {
     ExcelUtilityMethod.UseMethod(m_workBook, "Save", null);
 }
コード例 #23
0
 /// <summary>
 /// 选择此工作表
 /// </summary>
 public void Select()
 {
     ExcelUtilityMethod.UseMethod(m_workSheet, "Select", null);
     return;
 }
コード例 #24
0
ファイル: Workbook.cs プロジェクト: Woody-Hu/ExcelLateBinding
 /// <summary>
 /// 另存为
 /// </summary>
 /// <param name="strpath"></param>
 public void SaveAs(string strpath)
 {
     ExcelUtilityMethod.UseMethod(m_workBook, "SaveAs", new object[] { strpath });
 }
コード例 #25
0
        /// <summary>
        /// 新建一个文档
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public Workbook Add()
        {
            object thisObject = ExcelUtilityMethod.UseMethod(workbooks, "Add", null);

            return(new Workbook(thisObject));
        }