Friday, April 16, 2010 9:02 AM
I have to export all list items of a list to worddocument on one click. For example, i have created a list and added some rows of item, on the bottom of the list page there should be a button, on clicking on this button all rows item should be exported to word doc. this I have to do programmatically.
Code for sharepoint 2007
- Edited by Mike Walsh FIN Friday, April 16, 2010 9:08 AM NEVER say in a forum post that something is urgent. These are forums. Post and wait your turn. If you are in such a hurry ring MS Customer Support Services and pay for support.
Friday, April 16, 2010 9:16 AM
You should use OpenXML to generate the Word document from scratch. I suggest you to download the Open XML SDK 2.0 (http://www.microsoft.com/downloads/details.aspx?FamilyId=C6E744E5-36E9-45F5-8D8C-331DF206E0D0&displaylang=en), create a Word document (using Office) that seems similar to the one you would like to generate, then use the SDK tool to reflect the code.
See an intro here:
Announcing the Release of the December 2009 CTP for the Open XML SDK
Then look for the code block that is generated for an item from the document (probably a table row or something like that), and refactor that into a repeatable code block for each item.
I'm afraid you should create the code for yourself, especially if it is urgent for you.
Otherwise I'm to blog something similar within the next week, but it is not exactly the same.
Friday, April 16, 2010 9:32 AM
Thanks for response.
It's very difficult for me the way you suggested but I will try to achieve. i will be most obliged to you if you suggested the similar in coming few days.
Friday, April 16, 2010 10:21 AM
It is really not trivial, but after working with the SDK Tool with a few hours that is not so hard either.
Friday, April 16, 2010 12:11 PM
Please follow the post on how export custom list items to Excel in Sharepoint using SPGridview where using SPGridView you can easily export the data to .csv, .xls, .doc etc., files
but, you have to modify code on:
Line # 50: ExportToExcel("CountryState.xls" , myGridView); to ExportToExcel("CountryState.doc", myGridView);
Then after on,
Line # 99: HttpContext.Current.Response.ContentType = "application/ms-excel"; to HttpContext.Current.Response.ContentType = "application/ms-word";
Let me know in case if you need more information
Best Regards, G Vijai Kumar | My Sharepoint Blog
Friday, April 16, 2010 2:57 PM
the code is really helpul but can you suggest me how to call that webpart on clicking of 'Export' button in sharepoint designer. Actually I am confused how to provide url to call webpart on click event of the button. suppose I have created a webpart said ListExport.dll, I have put this dll into bin directory then what should be the url to call that dll and how to set for sending list information in query string.
Please don't mind I am beginner in sharepoint 2007.
Monday, April 19, 2010 8:39 AM
You could achieve this wtih a custom webpart, including Kumar or Peter’s suggestion.
If your concern was how to get current list information, then you could retrieve the information from SPContext.
Code like this:
private Button exportBtn;
protected override void CreateChildControls()
exportBtn = new Button();
exportBtn.Text = "ExportToWord";
//get list information from SPContext
exportBtn.Click += new EventHandler(exportButton_Click);
Some more reference for the solution:
Using Open XML SDK solution as Peter suggested:
Hope this can help.
- Marked As Answer by Chengyi Wu Friday, April 23, 2010 9:16 AM