A
AP
Hi,
I'm trying to modify a spreadsheet programmatically using c#. My code runs
fine, but when I open the file by double clicking on it in explorer, the
window never repaints itself. If I open excel first, then open the spread
sheet it repaints fine. Any ideas why this would be happening? My code is
pasted below. I am using excel 2000.
private void button1_Click(object sender, System.EventArgs e) {
openFileDialog1.ShowDialog(this);
string file = openFileDialog1.FileName;
Excel.Application ea = new Excel.ApplicationClass();
Workbook wb = ea.Workbooks.Open(file,Type.Missing,Type.Missing,Type.Missing,
Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missin
g,Type.Missing,Type.Missing,Type.Missing);
Name n;
for (int i = 1; i<= wb.Names.Count ;i++) {
n = wb.Names.Item(i, Type.Missing, Type.Missing);
if (n.Name.StartsWith("Update")) {
n.RefersToRange.Value2 = "Updated from code: " + i++;
}
}
object oTrue = true;
wb.SaveAs("d:\\temp\\temp.xls",Type.Missing,Type.Missing,Type.Missing,Type.M
issing,Type.Missing,Excel.XlSaveAsAccessMode.xlNoChange,Type.Missing
,Type.Missing,Type.Missing,Type.Missing);
ea.Quit();
}
Thanks,
Adam
I'm trying to modify a spreadsheet programmatically using c#. My code runs
fine, but when I open the file by double clicking on it in explorer, the
window never repaints itself. If I open excel first, then open the spread
sheet it repaints fine. Any ideas why this would be happening? My code is
pasted below. I am using excel 2000.
private void button1_Click(object sender, System.EventArgs e) {
openFileDialog1.ShowDialog(this);
string file = openFileDialog1.FileName;
Excel.Application ea = new Excel.ApplicationClass();
Workbook wb = ea.Workbooks.Open(file,Type.Missing,Type.Missing,Type.Missing,
Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missin
g,Type.Missing,Type.Missing,Type.Missing);
Name n;
for (int i = 1; i<= wb.Names.Count ;i++) {
n = wb.Names.Item(i, Type.Missing, Type.Missing);
if (n.Name.StartsWith("Update")) {
n.RefersToRange.Value2 = "Updated from code: " + i++;
}
}
object oTrue = true;
wb.SaveAs("d:\\temp\\temp.xls",Type.Missing,Type.Missing,Type.Missing,Type.M
issing,Type.Missing,Excel.XlSaveAsAccessMode.xlNoChange,Type.Missing
,Type.Missing,Type.Missing,Type.Missing);
ea.Quit();
}
Thanks,
Adam