using Microsoft.Office.Interop.Word;
using Microsoft.Office.Interop.Excel;
private void buttonX2_Click(object sender, EventArgs e)
{FileDialog saveFD = new SaveFileDialog();
saveFD.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
saveFD.Filter = "Excel文件(*.xls)|*.xls";
//saveFD.FileName = DateTime.Now.Date.ToShortDateString() + "log.xls";
if (saveFD.ShowDialog().ToString() == "OK")
{
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.ApplicationClass();
app.Visible = false;
Workbook wBook = app.Workbooks.Add(true);
Worksheet wSheet = wBook.Worksheets[1] as Worksheet;
((Microsoft.Office.Interop.Excel.Range)wSheet.Columns["B", Type.Missing]).ColumnWidth = 10;
((Microsoft.Office.Interop.Excel.Range)wSheet.Columns["C", Type.Missing]).ColumnWidth = 20;
wSheet.Cells[1, 1] = "NAME";
wSheet.Cells[1, 2] = "REFER";
wSheet.Cells[1, 3] = "STATIC Scanning";
wSheet.Cells[2, 1] = "1111";
wSheet.Cells[2, 2] = "22";
wSheet.Cells[2, 3] = "22";
app.DisplayAlerts = false;
app.AlertBeforeOverwriting = false;
//保存工作簿
wBook.Save();
//保存excel文件
app.Save(saveFD.FileName);
app.SaveWorkspace(saveFD.FileName);
app.Quit();
app = null;
}
}