I have a requirement to export my list data directly to document library as new Excel document.
I have used the following code to export to excel
function getLists() {
context = new SP.ClientContext();
web = context.get_web();
lists = web.get_lists();
context.load(lists,"Include(Id, Title, Hidden, ItemCount, Views)");
context.executeQueryAsync(onSuccess, onFail);
return false;
}
function onSuccess() {
var listsEnum = lists.getEnumerator();
while (listsEnum.moveNext()) {
var list = listsEnum.get_current();
if (list.get_title() == "Test") {
var title = list.get_title();
var viewCollection = list.get_views();
var viewInfo = 'Tasks list current views: \n\n';
var viewEnumerator = viewCollection.getEnumerator();
while (viewEnumerator.moveNext()) {
var view = viewEnumerator.get_current();
if (view.get_title() == "All Items") {
var viewGUID = view.get_id();
//Add the export link
document.getElementById("lnkExport").setAttribute('href', "../../_vti_bin/owssvr.dll?CS=109&Using=_layouts/query.iqy&List=" + list.get_id().toString() + "&View=" + viewGUID + "&CacheControl");
}
}
}
}
}
On success of this it returns me the owssvr.dll file which directly opens in Excel. But i don't want to download that file rather i want to directly upload that file into my Document Library as new Excel document.
If any one of you have gone through the same requirement then please let me know your thoughts.
Thanks in advance