I would need to pass the file name ref instead of giving string (full path) while opening or saving Excel in C#. Below is a code snippet
object fileName = (string)e.Argument;
object oMissing = System.Reflection.Missing.Value;
if (fileName.ToString().EndsWith("xlsx"))
{
Excel.Workbook wb;
object oMissing1 = Type.Missing;
var app = new Microsoft.Office.Interop.Excel.Application();
wb = app.Workbooks.Open(@"C:\Users\273714\Desktop\ProoferReport1.xlsx",
oMissing1, oMissing1, oMissing1, oMissing1,
oMissing1, oMissing1, oMissing1, oMissing1,
oMissing1, oMissing1, oMissing1, oMissing1,
oMissing1, oMissing1);
wb.SaveAs(@"C:\Users\273714\Desktop\Proofer Report2.xls",
Excel.XlFileFormat.xlExcel8, Type.Missing,
Type.Missing, Type.Missing, Type.Missing,
Excel.XlSaveAsAccessMode.xlExclusive,
Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
app.Quit();
app.Quit();
}
In case of a word document i can just open it like
oDoc = oWord.Documents.Open(ref fileName, ref oMissing,
ref readOnly, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref isVisible, ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
I need the same way of using the file name in Excel too. Any help will be grateful.