Message-ID: <606361042.7849.1711624116970.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_7848_1990103181.1711624116970" ------=_Part_7848_1990103181.1711624116970 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Generates an Excel binary or OOXML file and saves it as an attachment to= a SharePoint list item.
=20public static void Save(this ExcelTemplate template, Microsoft.SharePoint.S= PListItem listItem, string fileName)=20
Public Shared Sub Save(ByVal template As ExcelTemplate, ByVal listItem As M= icrosoft.SharePoint.SPListItem, ByVal fileName As String)=20
Save
will throw this exception if=20
null
(C#) or=20
Nothing
(VB.NET) is passed to the method.=20
ExcelWriter allows you to save in both the Excel 97-03 BIFF8 format (.xl= s) or the new Office Open XML (.xlsx) format. The template file must be of = the expected output format. Hence, if you wish to output .xls files, you mu= st start with a .xls template, and if you wish to output .xlsx files, you m= ust start with a .xlsx template. ExcelWriter does not support the creation = or editing of .xlsx files with the ExcelApplication object.
=20You can call Save
more than once for a single instance of <=
a href=3D"/display/EW9/ExcelTemplate" rel=3D"nofollow">ExcelTemplate. T=
his allows you to save more than one copy of a generated file, and/or both =
save the file on the server and stream it to the client.
//--- Retrieve current AllowUnsafeUpdates value bool currentAllowUnsafeUpdates =3D list.ParentWeb.AllowUnsafeUpdates; //--- You must allow unsafe updates in order for the file to be saved in th= e //--- List from a web application list.ParentWeb.AllowUnsafeUpdates =3D true; xlt.Save(listItem, "populated.xlsx"); //--- Update the list listItem.Update(); //--- Return the AllowUnsafeUpdates value to its original state list.ParentWeb.AllowUnsafeUpdates =3D currentAllowUnsafeUpdates;=20
'--- Retrieve current AllowUnsafeUpdates value Dim currentAllowUnsafeUpdates As Boolean =3D list.ParentWeb.AllowUnsafeUpda= tes '--- You must allow unsafe updates in order for the file to be saved in the '--- List from a web application list.ParentWeb.AllowUnsafeUpdates =3D True xlt.Save(listItem, "populated.xlsx") '--- Update the list listItem.Update() '--- Return the AllowUnsafeUpdates value to its original state list.ParentWeb.AllowUnsafeUpdates =3D currentAllowUnsafeUpdates=20