FileStream inputStream = new FileStream("../../Data/Test.xlsx", FileMode.Open, FileAccess.ReadWrite);
ExcelEngine engine = new ExcelEngine();
IApplication app = engine.Excel;
IWorkbook book = app.Workbooks.Open(inputStream);
book.SaveAs("../../Output/Resave.xlsx");
book.Close();
engine.Dispose();
inputStream.Close(); |
string clean1 = "SELECT * FROM [SOURCE$] WHERE [Region] = '" + regionBox.Items[r].ToString() + "'";
try
{
odcSOURCE.Open();
}
catch { }
OleDbDataAdapter dAdapter1 = new OleDbDataAdapter();
OleDbCommand cmd1 = new OleDbCommand(clean1, odcSOURCE);
cmd1.Parameters.Add("?", OleDbType.Integer, 5).Value = 1234;
cmd1.Parameters.Add("?", OleDbType.BSTR, 5).Value = "asdf";
dAdapter1.SelectCommand = cmd1;
System.Data.DataTable dt1 = new System.Data.DataTable();
dAdapter1.Fill(dt1);
odc.Close();
odc.Dispose();
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Open(exeDir + "\\Templates\\" + comboBox3.Text + "\\" + comboBox3.Text + " -Data.xlsx");
IWorksheet dataTab = workbook.Worksheets["DATA"];
try
{
dataTab.UsedRange.Clear();
}
catch { }
dataTab.ImportDataTable(dt1, true, 1, 1);
workbook.SaveAs(exeDir + "\\Templates\\" + comboBox3.Text + "\\" + comboBox3.Text + " -Data.xlsx");
workbook.Close(false);
excelEngine.Dispose();
dt1.Dispose();
GC.Collect();
GC.Collect();
The loop continues on to do various things.