I only wrote my data to 1 Excel sheet, but I want to make a new sheet and call it "xxx" and write data in it.
Here is what I have now:
private static Microsoft.Office.Interop.Excel.ApplicationClass appExcel;
private static Workbook newWorkbook_First = null;
private static _Worksheet objsheet = null;
excel_init("C:\\Users\\me\\Desktop\\excel2.xlsx");
for (int i = 1; i < WindowsXPLijst.Count; i++)
{
excel_setValue("B" + i, WindowsXPLijst[i]);
}
excel_close();
static void excel_init(String path)
{
appExcel = new Microsoft.Office.Interop.Excel.ApplicationClass();
if (System.IO.File.Exists(path))
{
// then go and load this into excel
newWorkbook_First = appExcel.Workbooks.Open(path, true, true);
objsheet = (_Worksheet)appExcel.ActiveWorkbook.ActiveSheet;
}
else
{
try
{
appExcel = new Microsoft.Office.Interop.Excel.ApplicationClass();
appExcel.Visible = true;
newWorkbook_First = appExcel.Workbooks.Add(1);
objsheet = (Microsoft.Office.Interop.Excel.Worksheet)newWorkbook_First.Sheets[1];
}
catch (Exception e)
{
Console.Write("Error");
}
finally
{
}
}
}
static void excel_setValue(string cellname, string value)
{
objsheet.get_Range(cellname).set_Value(Type.Missing, value);
objsheet.get_Range(cellname).Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
}
I don't have that much changed yet, because I have no idea how to change this function:
static void excel_setValue(string cellname, string value, string tab)
{
objsheet = tab // No ica what to exactly put here
}
{
excel_setValue("B" + i, WindowsXPLijst[i], "xxx");
}