c# - Creating and Saving an Excel File -


i have following code creates new excel file in c# code behind. when attempt save file user select location of save.

in method #1, can save file using workbook savecopyas without prompting user location. saves 1 file c:\temp directory.

method #2 save file in users\documents folder, prompt user select location , save second copy. how can eliminate first copy saving in users\documents folder?

excel.application oxl; excel._workbook owb; excel._worksheet osheet; excel.range orng;  try {     //start excel , application object.     oxl = new excel.application();     oxl.visible = false;      //get new workbook.     owb = (excel._workbook)(oxl.workbooks.add(missing.value));     osheet = (excel._worksheet)owb.activesheet;      // *****     osheet.cells[2, 6] = "ship to:";     osheet.get_range("f2", "f2").font.bold = true;      osheet.cells[2, 7] = sshiptoname;     osheet.cells[3, 7] = saddress;     osheet.cells[4, 7] = scitystatezip;     osheet.cells[5, 7] = scontactname;     osheet.cells[6, 7] = scontactphone;      osheet.cells[9, 1] = "shipment no:";     osheet.get_range("a9", "a9").font.bold = true;     osheet.cells[9, 2] = sjobnumber;      osheet.cells[9, 6] = "courier:";     osheet.get_range("f9", "f9").font.bold = true;     osheet.cells[9, 7] = scarriername;      osheet.cells[11, 1] = "requested delivery date:";     osheet.get_range("a11", "a11").font.bold = true;     osheet.cells[11, 2] = srequestdeliverydate;      osheet.cells[11, 6] = "courier acct no:";     osheet.get_range("f11", "f11").font.bold = true;     osheet.cells[11, 7] = scarrieracctnum;     // *****      method #1     //owb.savecopyas(@"c:\temp\" + sjobnumber +".xls");      method #2     oxl.saveworkspace(sjobnumber + ".xls"); } catch (exception theexception) {     string errormessage;     errormessage = "error: ";     errormessage = string.concat(errormessage, theexception.message);     errormessage = string.concat(errormessage, " line: ");     errormessage = string.concat(errormessage, theexception.source); } 

you can use savefiledialog , have user select location, u can use location when u call owb.savecopyas(userselectedlocation)


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -