/// <summary> /// 自动调整 /// </summary> public void AutoFit() { object temp = ExcelUtilityMethod.GetProperty(m_range, "EntireColumn"); ExcelUtilityMethod.UseMethod(temp, "AutoFit", null); return; }
/// <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 }); }
/// <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)); }
/// <summary> /// 将图片拷贝到剪切板 /// </summary> public void CopyPicture() { ExcelUtilityMethod.UseMethod(m_thisShape, "CopyPicture", new object[] { Microsoft.Office.Interop.Excel.XlPictureAppearance.xlScreen, Microsoft.Office.Interop.Excel.XlCopyPictureFormat.xlBitmap }); }
/// <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)); }
/// <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); } }
/// <summary> /// 退出 /// </summary> public void Quit() { ExcelUtilityMethod.UseMethod(latApplication, "Quit", null); try { Process tempProcess = Process.GetProcessById(pid); tempProcess.Kill(); } catch { ; } }
/// <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)); }
/// <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)); }
/// <summary> /// 设置图例 /// </summary> public void ApplyDataLabels() { ExcelUtilityMethod.UseMethod(m_chart, "ApplyDataLabels", null); }
/// <summary> /// 选择此工作表 /// </summary> public void Select() { ExcelUtilityMethod.UseMethod(m_workSheet, "Select", null); return; }
/// <summary> /// 另存为 /// </summary> /// <param name="strpath"></param> public void SaveAs(string strpath) { ExcelUtilityMethod.UseMethod(m_workBook, "SaveAs", new object[] { strpath }); }
/// <summary> /// 保存 /// </summary> public void Save() { ExcelUtilityMethod.UseMethod(m_workBook, "Save", null); }
/// <summary> /// 关闭工作簿 /// </summary> public void Close() { ExcelUtilityMethod.UseMethod(m_workBook, "Close", new object[] { null, null, null }); }
/// <summary> /// 关闭此文档 /// </summary> public void Close() { ExcelUtilityMethod.UseMethod(workbooks, "Close", null); }
/// <summary> /// 新建一个文档 /// </summary> /// <param name="path"></param> /// <returns></returns> public Workbook Add() { object thisObject = ExcelUtilityMethod.UseMethod(workbooks, "Add", null); return(new Workbook(thisObject)); }