Office Integration Pack Sample.

Office Integration Pack is a popular and free LightSwitch extension created by Steve Hansen from Grid Logic. Now in Version 1.1. It’s very useful to Import and Export data with Microsoft Office. It can be used as a reporting tool but the application’s user will need to have Microsoft Office installed for this to work.

There is a simple application to demonstrate the product. It’s called BookStoreApplication.
Testing it with Visual Studio 2012 Update 3, it’s required to upgrade the project. There is also an issue when running the project, it is in the screen called ExportToWord_SpecificFields. The error is “Overload resolution failed because no accessible ‘Export’ accepts this number of arguments.”

To correct this you need to add the missing parameter “BuildColumnHeadings”, it’s a boolean. I commented the line with the error and added a new line.

Namespace LightSwitchApplication
   Public Class ExportToWord_SpecificFields
      Private Sub ExportToWord_Execute()
         'Export a specific set of fields to a new document table
         Dim fields as new List(Of String)

         'OfficeIntegration.Word.Export(Me.Books, fields, UseActiveDocument:=False)
         OfficeIntegration.Word.Export(Me.Books, False, fields, UseActiveDocument:=False)
      End Sub
   End Class
End Namespace

Now it runs Ok.

Another example:

string MyDocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string WordFile = MyDocs + @"\filename.docx";
if (File.Exists(WordFile))
   // créate column mappings
   List<OfficeIntegration.ColumnMapping> mapContent = new List<OfficeIntegration.ColumnMappings>();
   mapContent.Add(new OfficeIntegration.ColumnMapping("Contact Name", "Contact", this.OT.Contact == null ? "---" : this.OT.Contact ));
   // calling a query MyQuery1 with one parameter Id
   var query1 = this.DataWorkspace.ApplicationData.MyQuery1(this.OT.Id);
   // Mapping for the table
   List<OfficeIntegration.ColumnMapping> mapTable = new List<OfficeIntegration.ColumnMapping>();
   mapTable.Add(new OfficeIntegration.ColumnMapping("Description", "Description"));
   // using OfficeIntegration
   dynamic doc = OfficeIntegration.Word.GenerateDocument(WordFile, this.OT, mapContent);
   // making Word not visible
   doc.Application.Visible = false;
   // exporting a query to Word
   OfficeIntegration.Word.Export(doc, "TableDG", 1, false, query1, mapTable);
   // saving to pdf
   OfficeIntegration.Word.SaveAsPDF(doc, MyDocs + "\\filename.pdf", true);
   if (doc != null)
      // exiting word
This entry was posted in LightSwitch and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s