Tag Archives: excelwriter

PivotTables are not displaying correctly

Problem

After creating or modifying a PivotTable with ExcelWriter 8.4 or later, the PivotTable has not changed or is empty.

Solution

ExcelWriter does not have the ability to render PivotTables. Changes made to a PivotTable using ExcelApplication will not take effect until the PivotTable is refreshed. There are several ways to refresh the PivotTable:

  1. If you are editing an existing PivotTable, in the original file, go to PivotTable Options > Data > Check off “Refresh data when opening the file.” This will ensure that Excel refreshes the PivotTable as soon as the output is opened.
  2. If you are creating a new PivotTable from scratch, make sure to set the PivotTable.PivotTableSettings.RefreshOnOpen to true. This will force the PivotTable to refresh automatically when the output is opened.
  3. If you don’t want to have Excel refresh the PivotTable when the workbook opens, you can refresh the PivotTable manually or with a macro. Right-click the PivotTable and select Refresh.

We encourage users to keep “Refresh on Open” enabled when working with PivotTables in ExcelWriter to make sure that modified PivotTables load correctly in Excel.

ExcelWriter Error: Resulting sheet would have more rows than are permitted by the Excel format

Problem

The Excel .xls binary format has a limit of 65536 rows per worksheet. If you are importing data with ExcelWriter’s ExcelTemplate object (or our SSRS renderer, which uses the ExcelTemplate object) it is possible to get an error that Excel’s row limit was exceeded even though you know you have imported much fewer than 65K rows.

This problem is usually caused by cells or formulas that already exist in the template file. When ExcelWriter populates a spreadsheet with the ExcelTemplate object, it inserts a new row for every row of data and pushes all existing rows down. If the total number of pushed down rows plus inserted rows exceeds Excel’s limit, an exception will be thrown. Then, after the data has been imported, ExcelWriter goes through the entire workbook and updates any formulas that reference the data marker cells, stretching the formulas to include all the newly inserted rows. If the cell range in a formula is stretched beyond Excel’s row limit, again an exception will be thrown.

Solution

Cells

Sometimes people take a previously populated report and turn it into a template. They may have cleared the cell values, but the template may still contain many rows of cells that are blank or contain only formatting. These rows will be pushed down when the data is imported.

The solution is to clean up the template file by actually deleting all unnecessary rows and columns rather than just clearing cell values. Also, it’s generally a good idea to set background formatting using row or column headers rather than by selecting large areas of cells.

Formulas

Formulas can be found in many parts of a workbook, including cells, charts, conditional formatting, and named ranges. Make sure that all formulas reference the minimum number of rows necessary and bear in mind that ExcelWriter will stretch certain formulas when new rows are inserted.

Hidden named ranges

It is important to know that Excel sometimes creates hidden named ranges behind the scenes for internal purposes. You won’t be able to find them through the Excel UI, but if they reference data marker cells, ExcelWriter will update them. Common cases where Excel created hidden named ranges are when the user applies an AutoFilter or AdvancedFilter to a range of cells. This occurs whether the filter is applied from the Excel UI or from a VBA macro. For this reason, check your macros carefully to make sure they are not applying any filters to unecessarily large cell ranges that include data markers. If you have any unnecessarily large hidden named ranges in your macros, you can modify them by changing the VBA code and running the macro again. If you are having trouble modifying or removing hidden named ranges, you can write some VBA code to do it. The names always end in “`_FilterDatabase”

Tip: If you have Excel 2007 or above, here is a quick way to see if you have any hidden named ranges in an .xls file without writing any VBA:

  1. In Excel, save a copy of the template file as .xlsx or .xlsm
  2. Rename to .zip and unzip the file
  3. In the subdirectory “xl”, open the file workbook..xml
  4. Look in the Section
  5. Look for defined names that end in “_FilterDatabase”. Here is an example of something you might see: <definedName name="xlnm.FilterDatabase” localSheetId=”3″ hidden=”1″> Data!$A$1:$BQ$65000
  6. If you temporarily change hidden to 0, it will show up in Excel under the named item manager.

Note: We don’t recommend permanently modifying or removing these hidden named ranges in the XML directly as that could have unexpected results.

FitToPagesTall and FitToPagesWide settings do not take effect

Problem

FitToPagesTall and FitToPagesWide settings do not take effect unless Zoom is explicitly set to false.

Solution

FitToPagesTall, FitToPagesWide and Zoom are properties of the PageSetup object of the ExcelWriter Application object.

The Page Setup dialog in Microsoft Excel allows you to select one of the following two options:

  1. Adjusting the worksheet so that it fits to the dimension of “x” number of pages width-wise and/or length-wise.
  2. Adjusting the worksheet so that it prints to a certain percentage of the original size, ranging between 10 and 400 percent.

The equivalent properties in ExcelWriter are:

The Zoom property has a default value of “True” and “100” percent. This means that even if the Zoom is not explicitly set in your code, these values will be assumed. Any values provided for FitToPagesTall or FitToPagesWide will be ignored. If you want to use these properties, you must explicitly change the value of Zoom to “False”:

worksheet.PageSetup.Zoom = false; worksheet.PageSetup.FitToPagesTall = 2; worksheet.PageSetup.FitToPagesWide = 2;

Install Error: System appears to have an unrecognized version of J#

Problem

The following error is returned while attempting to install OfficeWriter 3.9 or below:

The System appears to have .NET 2.0 and an unrecognized version of J#. Please install J# 2.0 if you wish to use ExcelWriter .NET or WordWriter.

Starting with version 4, OfficeWriter has been written completely in C# and no longer requires the J# runtime. However, customers installing version 3.x of OfficeWriter do need the J# runtime. The version of J# should match the installed version of the .NET framework.

Solution

Install the J# redistributable that matches the .NET framework that you are using in your application.

Note: Microsoft has not released a J# redistributable that matches .NET 4.0 framework. To use OfficeWriter with .NET 4.0, you will need to upgrade to OfficeWriter 4 or later.

Files generated by OfficeWriter do not open in the browser

Problem

When OpenInBrowser in the Save method is set to true, the Excel spreadsheet or Word document does not open in the Internet Explorer Browser window as expected. Instead, the spreadsheet opens in Excel or the document opens in Word.

Solution

Using a browser other than Internet Explorer

The plugin that is used to display Office files in the browser is only available in Internet Explorer, so other browsers cannot display Excel or Word files within the browser. However, you can set whether you want to always open the files in Excel or Word, or save them to disk by default.

Firefox:

When a user is sent an Excel or Word file, a dialog box prompting to Open or Save the file pops up. The user can choose an option and then check the “Do this automatically for files like this from now on” box to have it remember this choice.

Chrome:

Chrome defaults to saving the file to disk. If you want to open a file type automatically in Excel or Word, download a file of that type. Once the file is downloaded, right-click the file in the download bar at the bottom of the browser. Select “Always open files of this type”.

Using Internet Explorer

It is likely that the “Browse in Same Window” is disabled for the file types (XLS, XLSX, XLSM, DOC, DOCX, DOCM).

Previously, this option was available under Folder Options > File Types > Select a file type > Check Browse in the same Window.

Starting in Windows Vista, this option is no longer exposed and the registry needs to be modified to enable certain file types to open in the browser. This Microsoft Knowledge Base article explains how to enable the behavior by modifying the registry: A new window opens when you try to view a 2007 Microsoft Office program document in Windows Internet Explorer 7 or Internet Explorer 8.

Excel or Word file generated by OfficeWriter opens in protected view (yellow)

Problem

A report generated using ExcelWriter or WordWriter opens and there is a yellow warning banner saying that the file has been opened in Protected View.

Solution

Starting in Office 2010, Microsoft introduced a security feature that scans files before opening them in Excel or Word. If there is something wrong with the file format definition, it will open in Protected Mode with a red warning banner.

One of the common scenarios for opening a file in Protected View is opening the file from an unsafe location, such as the Temporary Internet Files folder. This means that if the file is streamed to an end-user, it will open in protected view.

For more information about Protected View settings in Office 2010, please refer to this Microsoft TechNet article on how to configure Protected View settings in Office 2010.