Moti Mashiah
asked on
Asp.net mvc
Hi Guys,
I'm using "Microsoft.Office.Interop. Excel" to export my form to excel spreadsheet and it is working fine and save it in the location I provided, but what if I want to let user to save it whenever he wants, like to popup window dialog and let him choose the path?
Here is my code:
I'm using "Microsoft.Office.Interop.
Here is my code:
public ActionResult Exporttoexcel()
{
Itemmodel itm = new Itemmodel();
try
{
Excel.Application application = new Excel.Application();
Excel.Workbook workbook = application.Workbooks.Add(System.Reflection.Missing.Value);
Excel.Worksheet worksheet = workbook.ActiveSheet;
worksheet.Cells[1, 1] = "Itemlookup";
worksheet.Cells[1, 2] = "Description";
worksheet.Cells[1, 3] = "Price";
worksheet.Cells[1, 4] = "Cost";
int row = 2;
foreach(var it in itm.Findall())
{
worksheet.Cells[row, 1] = it.Itemlookup;
worksheet.Cells[row, 2] = it.Description;
worksheet.Cells[row, 3] = it.Price;
worksheet.Cells[row, 4] = it.Cost;
row++;
}
Formatexcel(worksheet, row);
workbook.SaveAs("d:\\test\\Item_list.xlsx");
workbook.Close();
Marshal.ReleaseComObject(workbook);
application.Quit();
Marshal.FinalReleaseComObject(application);
}
catch(Exception ex)
{
ViewBag.message = ex.Message;
}
return RedirectToAction("Index");
}
ASKER
Thank you for your answer:
Can you show some example to how i pass the fdb to workbook.SaveAs("d:\\test\ \Item_list .xlsx");
Can you show some example to how i pass the fdb to workbook.SaveAs("d:\\test\
ASKER
Or should I use it without saving. just popup dialog.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
There is away to avoid saving to the server ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dustin,
This is actually avoid me from saving the file on the server?
This is actually avoid me from saving the file on the server?
Open in new window
Then you can save to the path.