public class ExcelHelper
{
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);
protected void Button1_Click(object sender, EventArgs e)
{
var excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
excel.Workbooks.Open("d:\aaa.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
IntPtr t = new IntPtr(excel.Hwnd);
int k = 0;
GetWindowThreadProcessId(t, out k);
System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(k);
p.Kill();
}
static Microsoft.Office.Interop.Excel.Application xlApp = null;
static ExcelHelper()
{
}
public static bool InitXl()
{
try
{
if (xlApp == null)
xlApp = new Microsoft.Office.Interop.Excel.Application();// new Microsoft.Office.Interop.Excel.ApplicationClass();
return true;
}
catch (Exception ex)
{
release();
MyMsgBox.ShowError(ex.Message);
}
return false;
}
public bool CreateLine3D(Workbook m_workBook,Range dataRange)
{
//添加一个页面
m_workBook.Charts.Add(Type.Missing, Type.Missing, 1, Type.Missing);
//CreateTitle(int row, int columnbegin, int columnend, string title);
//定义图类型
m_workBook.ActiveChart.ChartType = XlChartType.xlLine;
//图数据源(根据列的索引得到当前绑定列的名称)
m_workBook.ActiveChart.SetSourceData(dataRange, XlRowCol.xlColumns);
//图形宽和高
// m_workBook.ActiveChart.ChartArea.Width = papam.PicWidth;
// m_workBook.ActiveChart.ChartArea.Height = papam.PicHeight;