Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Introducedin
7.1.0.1855
7.1.0.1855
Description

Excerpt

Saves a specified Workbook as a BIFF8 format (Excel 97 or later) .xls file.

Signature
C#
C#
public static void Save(this ExcelApplication excelApplication, Workbook workbook, Microsoft.SharePoint.SPDocumentLibrary docLib, String fileName, bool overwrite)
Signature
vb.net
vb.net
Public Overridable Sub Save(ByVal excelApplication As ExcelApplication, ByVal workbook As Workbook, ByVal docLib As Microsoft.SharePoint.SPDocumentLibrary, ByVal fileName As String, ByVal overwrite As Boolean)
Parameters
Param
excelApplication
excelApplication

The current ExcelApplication object which is saving the workbook to file

Param
workbook
workbook

A Workbook object representing the workbook to save.

Param
docLib
docLib

SharePoint Document Library that contains the Excel spreadsheet being opened

Param
fileName
fileName

Specifies a file name for the Workbook. ExcelWriter will save the file to the document library using this name. If a file with the same name exists, it will be overwritten by the new Excel file if the overwrite parameter is set to True.

Param
overwrite
overwrite

Set to True to overwrite an Excel file if one already exists by that name in the Document Library

Exceptions
Exception
System.Exception
System.Exception

If there is a problem creating, opening, or writing to the file specified, or reading from the workbook object.

Remarks
Note

This is an extension method for the ExcelApplication object to be used for saving spreadsheets to SharePoint Document Libraries. To use this method, you must add a reference to SoftArtisans.OfficeWriter.ExcelWriter.SharePointIntegration.dll

Example
Code Block
csharp
csharp
titleC#
//--- Retrieve current AllowUnsafeUpdates value
bool currentAllowUnsafeUpdates = documentLibrary.ParentWeb.AllowUnsafeUpdates;

//--- You must allow unsafe updates in order for the file to be saved in the
//--- Document Library from a web application
documentLibrary.ParentWeb.AllowUnsafeUpdates = true;
xla.Save(wb, documentLibrary, "populated.xls", true);

//--- Update the document library
documentLibrary.Update();

//--- Return the AllowUnsafeUpdates value to its original state
documentLibrary.ParentWeb.AllowUnsafeUpdates = currentAllowUnsafeUpdates;
Code Block
vb.net
vb.net
titlevb.net
'--- Retrieve current AllowUnsafeUpdates value
Dim currentAllowUnsafeUpdates As Boolean = documentLibrary.ParentWeb.AllowUnsafeUpdates

'--- You must allow unsafe updates in order for the file to be saved in the
'--- Document Library from a web application
documentLibrary.ParentWeb.AllowUnsafeUpdates = True
xla.Save(wb, documentLibrary, "populated.xls", True)

'--- Update the document library
documentLibrary.Update()

'--- Return the AllowUnsafeUpdates value to its original state
documentLibrary.ParentWeb.AllowUnsafeUpdates = currentAllowUnsafeUpdates