1
votes

I have large report and each row contains hyperlink.

Report containing 50k or more rows is exported to excel.

After export I try to open xlsx file and get message telling me that file contains error. It also suggests to do file recovery

After recovery message shows that hyperlinks were removed. I can open file but links are no longer working.

I tried to open exported file with c# openxml sdk library and got error message telling that file contains incomplete element but i was unable to find which element it is

However, when report has less than 49k rows, exported file is opened succesfully and all hyperlinks are working. When report is exported to pdf or doc, hyperlinks are also working I use report server vesion 12.0.2269.0

Does anyone know how to resolve this issue ?

2

2 Answers

1
votes

Usually, when I have experienced this sort of issue after an Excel file exported from SSRS, I find there is something in the data that Excel has issue with. A hidden character, perhaps. The export works, opening the file is when the problem starts.

To deal with this situation I created a user defined function (UDF) in SQL Server to remove any characters that I know Excel will choke on. Below is an example of one I use.

CREATE FUNCTION [dbo].[udf_CleanData]
(
    @data text
)

RETURNS varchar(max)

AS

BEGIN
    DECLARE @cdata varchar(max) = @data

    SELECT @cdata = REPLACE(@cdata, char(20), '') -- double quote 
    SELECT @cdata = REPLACE(@cdata, char(21), '') -- bullet
    SELECT @cdata = REPLACE(@cdata, char(13), '') -- carriage return
    SELECT @cdata = REPLACE(@cdata, char(10), '') -- line feed
    SELECT @cdata = REPLACE(@cdata, char(18), '') -- single quote right
    SELECT @cdata = REPLACE(@cdata, char(17), '') -- single quote left
    SELECT @cdata = REPLACE(@cdata, char(22), '') -- dash

    RETURN @cdata
END

You can adjust this any way you want to meet your need. This works for what I need, and that is removing all the strange characters in a text field that the dev team thought would be good to use for formatting on the front end application.

Usage:

SELECT dbo.udf_CleanData(Field1) AS CleanField1 FROM Table1

If the hyperlink you are reporting has anything unusual in it, this might remove that. If you are building the hyperlink from various pieces of data, some or all of the fields may need to be scrubbed. This is something where you will have to go through a bit of trial and error.

Other times when I have had this issue, there is an expression in the RDL that ends up calculating to either NaN, or Infinity. The Excel file after export seems to have issue with this except when exporting to an older version of Excel, like 2003.

The best way to handle this situation is adjust your expressions to check for the possibility that the final value could be out of whack, and default the value to something else, or round the value to something reasonable. This is similar to checking that a denominator is not zero before doing division.

=IIf(Fields!Total.Value > 0, Fields!Count.Value/Fields!Total.Value, 0)

There are plenty of questions about this type of thing with good solutions here on SO, so I won't list a bunch of expressions here related to data checking.

The other way to handle this is to always export to an earlier version of Excel, but that may not be any easy option, or an option at all. Usually, I only see that as an option on a report subscription, but not in the development tools.

Good luck to you!

0
votes

I have also faced this issue when exporting SSRS reports to Excel. The reason in my case was that Excel can only handle 66530 hyperlinks -

https://support.office.com/en-us/article/Excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3#ID0EBABAAA=2016,_2013

Confirm again if you get this issue the moment you go over 50k (in which case the reason could be what R Richards suggests), or if it is 66530 links that cause the spreadsheet to break.

I havent found a way get around this limitation of Excel, so the only way I can think of to resolve this is to not have hyperlinks in the exported excel file at all.

If you can live without hyperlinks in the exported file, you can disable them in the report using the Globals!RenderFormat property of the SSRS report. The expression to use on the cells to not have hyperlinks if the requested format is EXCEL would be -

=IIF(Globals!RenderFormat.Name="EXCELOPENXML" ,True,False)