1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Excel;
using Excel = Microsoft.Office.Interop.Excel;
namespace test
{
public class ToExcel
{
public ToExcel()
{
Excel.Application ObjExcel = new Microsoft.Office.Interop.Excel.Application();
string model = @"C:\template.xls";
string pathDestination = @"C:\target.xls";
Excel.Workbook ObjWorkBookTemp = ObjExcel.Workbooks.Open(model, 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);
Excel.Worksheet wh1 = (Excel.Worksheet)ObjWorkBookTemp.Sheets[1];
//wh1.get_Range("A" + 1, Type.Missing).Value2 = string.Format("COUCOU");
ObjWorkBookTemp.SaveAs(pathDestination, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
ObjWorkBookTemp.Close(false, Type.Missing, Type.Missing);
}
}
} |
Partager