I have this code that will create an excel file and a worksheet, and then paste the same values.
The problem I am facing is that I cannot save a file with a name giving ten pieces.
I used SaveAs, but did not work:
wb.SaveAs(@"C:\mymytest.xlsx", missing, missing, missing, missing,
missing, XlSaveAsAccessMode.xlExclusive, missing, missing, missing, missing, missing);
this line of code will give me this error:
Microsoft Office Excel cannot access the file "C: \ A3195000". There are several possible reasons:
• The file name or path does not exist. • The file is being used by another program. • The book you are trying to save has the same name as the current open book.
We advise you to solve this problem.
here is my code:
private void button1_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
if (xlApp == null)
{
MessageBox.Show("EXCEL could not be started. Check that your office installation and project references are correct.");
return;
}
xlApp.Visible = true;
Workbook wb = xlApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Worksheet ws = (Worksheet)wb.Worksheets[1];
if (ws == null)
{
MessageBox.Show("Worksheet could not be created. Check that your office installation and project references are correct.");
}
Range aRange = ws.get_Range("C1", "C7");
if (aRange == null)
{
MessageBox.Show("Could not get a range. Check to be sure you have the correct versions of the office DLLs.");
}
Object[] args = new Object[1];
args[0] = 6;
aRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, aRange, args);
aRange.Value2 = 8;
}
source
share