C# で Excel を開いたり保存したりするときに、文字列 (フル パス) を指定する代わりに、ファイル名 ref を渡す必要があります。以下はコードスニペットです
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();
}
Word文書の場合、次のように開くことができます
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);
Excelでもファイル名を使用するのと同じ方法が必要です。どんな助けでも感謝します。