I will change the color of some Excel Cells and I use the following function for it:
private void FormatFile(Excel.Borders _borders)
{
_borders[Excel.XlBordersIndex.xlEdgeLeft].LineStyle = Excel.XlLineStyle.xlContinuous;
_borders[Excel.XlBordersIndex.xlEdgeRight].LineStyle = Excel.XlLineStyle.xlContinuous;
_borders[Excel.XlBordersIndex.xlEdgeTop].LineStyle = Excel.XlLineStyle.xlContinuous;
_borders[Excel.XlBordersIndex.xlEdgeBottom].LineStyle = Excel.XlLineStyle.xlContinuous;
_borders.Color = ConsoleColor.Black;
_range = _xlWorkSheet.get_Range("A1:AG100");
_range.EntireColumn.AutoFit();
_range.EntireRow.AutoFit();
Excel.Range colorRange;
colorRange = _xlWorkSheet.get_Range("y1", "ag100");
colorRange.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightGray);
}
It works fine but when the Program will save the file it comes this screen:
Do you have an idea how to change it that I don't become that window ?
I save the file with this function:
internal string SaveFile(string writePath)
{
FormatCells(_xlWorkSheet.Cells.Borders);
string fileName = string.Format("{0}_{1}.xlsx","running_", DateTime.Now.ToString("yyyyMMdd_HHmmss"));
_xlWorkBook.SaveAs(Path.Combine(writePath, fileName), Excel.XlFileFormat.xlWorkbookNormal, misValue,
misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
_xlWorkBook.Close(true, misValue, misValue);
_xlApp.Quit();
ReleaseObject(_xlWorkSheet);
ReleaseObject(_xlWorkBook);
ReleaseObject(_xlApp);
return fileName;
}