Security Warning

I am saving an Excel 2007 file with the following code:

wbReport.Save(Me.Response, strReportTitle, ContentDisposition.Attachment, New OoxmlSaveOptions)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

HttpContext.Current.Response.End()

When the Excel file opens up I get the “Security Warning Data connections have been disabled” alert toolbar at the top of my worksheet. Unless the end user selects it and changes to the enable content option, the pivot tables within the file do not refresh on file open as they are set to do. Is there a way to get around the security warning? I am using Aspose Cells 6.0.1.0.

Hi,


I tested your scenario and it works fine. I do not get security warning or any other alert when I response the generated Excel file into MS Excel on the fly. Here is my complete sample code (based .cs file):

Sample code:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Aspose.Cells;
using Aspose.Cells.Pivot;

public partial class Default21 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Instantiating an Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the newly added worksheet
Worksheet sheet = workbook.Worksheets[0];
Cells cells = sheet.Cells;
//Setting the value to the cells
Aspose.Cells.Cell cell = cells[“A1”];
cell.PutValue(“Sport”);
cell = cells[“B1”];
cell.PutValue(“Quarter”);
cell = cells[“C1”];
cell.PutValue(“Sales”);
cell = cells[“A2”];
cell.PutValue(“Golf”);
cell = cells[“A3”];
cell.PutValue(“Golf”);
cell = cells[“A4”];
cell.PutValue(“Tennis”);
cell = cells[“A5”];
cell.PutValue(“Tennis”);
cell = cells[“A6”];
cell.PutValue(“Tennis”);
cell = cells[“A7”];
cell.PutValue(“Tennis”);
cell = cells[“A8”];
cell.PutValue(“Golf”);
cell = cells[“B2”];
cell.PutValue(“Qtr3”);
cell = cells[“B3”];
cell.PutValue(“Qtr4”);
cell = cells[“B4”];
cell.PutValue(“Qtr3”);
cell = cells[“B5”];
cell.PutValue(“Qtr4”);
cell = cells[“B6”];
cell.PutValue(“Qtr3”);
cell = cells[“B7”];
cell.PutValue(“Qtr4”);
cell = cells[“B8”];
cell.PutValue(“Qtr3”);
cell = cells[“C2”];
cell.PutValue(1500);
cell = cells[“C3”];
cell.PutValue(2000);
cell = cells[“C4”];
cell.PutValue(600);
cell = cells[“C5”];
cell.PutValue(1500);
cell = cells[“C6”];
cell.PutValue(4070);
cell = cells[“C7”];
cell.PutValue(5000);
cell = cells[“C8”];
cell.PutValue(6430);

PivotTableCollection pivotTables = sheet.PivotTables;
//Adding a PivotTable to the worksheet
int index = pivotTables.Add("=A1:C8", “E3”, “PivotTable2”);
//Accessing the instance of the newly added PivotTable
PivotTable pivotTable = pivotTables[index];

pivotTable.RowGrand = true;
pivotTable.ColumnGrand = true;
//Draging the first field to the row area.
pivotTable.AddFieldToArea(PivotFieldType.Row, 0);
//Draging the second field to the column area.
pivotTable.AddFieldToArea(PivotFieldType.Column, 1);
//Draging the third field to the data area.
pivotTable.AddFieldToArea(PivotFieldType.Data, 2);


workbook.Save(this.Response, “my_pvtTable.xlsx”, ContentDisposition.Attachment, new OoxmlSaveOptions());
HttpContext.Current.Response.End();
}
}

I have attached a screen shot of the output file into MS Excel 2010.

I am using v6.0.1. If you still could not evaluate, please create a sample web project(we forms + vb/cs), zip it and post it here, we will check it soon.

By the way, could you check to remove all code segments of Aspose.Cells, and just open the file (having your pivot table/data etc.) with System.IO.FileStream, then export the file by the Response object without involving Aspose.Cells API if MS Excel gives you the same warning message.


Here is a sample of what I'm trying to code with a workbook attached which will reproduce the error I'm seeing.

Protected Sub btnAspose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAspose.Click

Dim strReportTitle As String = "Aspose_Test.xlsx"

Dim strFileSystemPath As String = "~/Reports/AsposeExample.xlsx"

Dim strReportPath As String

Dim wbReport As Workbook

Dim wsReport As Worksheet

Dim Cells As Cells

Dim Cell As Cell

Try

strReportPath = System.Web.HttpContext.Current.Server.MapPath(strFileSystemPath)

wbReport = New Workbook(strReportPath)

wsReport = wbReport.Worksheets(1)

Cells = wsReport.Cells

Cell = Cells("A5")

Cell.PutValue("Golf")

Cell = Cells("A6")

Cell.PutValue("Golf")

Cell = Cells("A7")

Cell.PutValue("Outdoors")

Cell = Cells("A8")

Cell.PutValue("Outdoors")

Cell = Cells("B5")

Cell.PutValue("Golf Balls")

Cell = Cells("B6")

Cell.PutValue("Clubs")

Cell = Cells("B7")

Cell.PutValue("Tents")

Cell = Cells("B8")

Cell.PutValue("Fishing Poles")

Cell = Cells("C5")

Cell.PutValue(25)

Cell = Cells("C6")

Cell.PutValue(21)

Cell = Cells("C7")

Cell.PutValue(42)

Cell = Cells("C8")

Cell.PutValue(58)

Cell = Cells("D5")

Cell.PutValue(34)

Cell = Cells("D6")

Cell.PutValue(14)

Cell = Cells("D7")

Cell.PutValue(62)

Cell = Cells("D8")

Cell.PutValue(71)

wbReport.Save(Me.Response, strReportTitle, ContentDisposition.Attachment, New OoxmlSaveOptions)

HttpContext.Current.Response.End()

Catch ex As Exception

Response.Write("

Error: " & ex.Message.ToString & "

")

End Try

End Sub

Hi,


Opening your template file “AsposeExample.xlsx” produces the security alert and hence it will be displayed in protected view, see the attached screen shots that is taken opening the file into MS Excel 2010.


Thank you.

So in this type of situation how do you suggest we update pivot tables when the underlying data source changes?

Hi,


Please clear the protection in your source file and re-attach it here, We will further investigate your issue.

Thank you.

Clear the protection? I don’t know what your refering to.

Hi,


I mean your template file is opened in Protected View (in MS Excel 2010) by default as my attached screen shot showed in the previous reply. Could you fix it or do something (e.g you may give us other template file that should be opened fine into MS Excel 2010 and should not be opened in Protected View with warning message etc.) to attach the file here again here, so that we could check your issue soon.

Thank you.

There is nothing I’m doing to create that Protected View. I’ve never seen it before and can’t reproduce it in Excel 2007, even when I open the file attached above. It must be a feature within Excel 2010. I have reattached the original file if that helps.

Hi,


This file also gives the Protection warning message, please let us know how did you generate this source file? Did you create it manually by using MS Excel or some other software? We need to investigate the issue.

Thank you.

It was created manually from nothing more than a new (blank) Excel workbook.

As an alternative to setting the pivot tables to refresh on open I’ve tried to update all pivot tables via code just before the save line like this:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

For Each xlsWorksheet In xlsWorkbook.Worksheets

For Each xlsPivotTable In xlsWorksheet.PivotTables

xlsPivotTable.RefreshData()

xlsPivotTable.CalculateData()

Next

Next

My problem here is I’m getting this error at the RefreshData method:

Error: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

I can’t figure out what the Index parameter is referring to and I’m having trouble creating sample code to recreate the error.

Hi,


We appreciate if you could create a sample project, zip it (with all the files) and post it here to reproduce the issue on our end, we will check your issue soon.

Thank you.

Ok, while creating a sample project for you I discovered the object causing the problem. My pivot table has a calculated field in it. On click of the button you get an error “Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index” thrown at the xlsPivotTable.RefreshData() line. If you go into the Excel template file and remove the calculated field from the pivot table, all is fine and dandy. Can you find a solution for this problem?

Hi,


I still could not evaluate/check your issue, your provided sample project does not have its source code e.g .VB file, it has only Default.aspx file and a template Excel file in the “Reports” sub-folder. Kindly give us your runnable project/solution, so, that we could evaluate your issue soon.

thank you.

Hi,


Thanks for the project.
After an initial test running your project, I have found the error “Inded was out of range…” on PivotTable.RefreshData/CalculateData method. Moreover, If I simply comment out the lines in your project, e.g
’xlsWorkbook.Worksheets.Names.Remove(“Raw_Data”)
'xlsWorksheet.Cells.DeleteRows(4, 4)

'rgeDtaSource = xlsWorksheet.Cells.CreateRange(3, 0, 6, 4)
'rgeDtaSource.Name = "Raw_Data"

still I got the error on the lines:

For Each xlsWorksheet In xlsWorkbook.Worksheets
For Each xlsPivotTable In xlsWorksheet.PivotTables
xlsPivotTable.IsAutoFormat = False
xlsPivotTable.ShowDrill = False
xlsPivotTable.RefreshData()
xlsPivotTable.CalculateData()
Next
Next

I have logged a ticket for the issue with an id: CELLSNET-29876. We will look into your issue and get back to you soon.

Thank you.

Hi,

At present, we could not calculate the data if the pivottable has calculatedfield. We will support it later.

Please try this sample code.

C#


xlsPivotTable.RefreshData();

xlsPivotTable.RefreshDataOnOpeningFile = true;

// xlsPivotTable.CalculateData();



Well that’s very disappointing. Without supporting calculated fields that just puts more work back on IT (me) to create any calculation an end user may need in the database since they cannot create them their self in the spreadsheet.

Setting RefreshDataOnOpeningFile = True just brings me back to the original problem I had when I started this thread. Microsoft’s overprotective security alert disables the pivot table refresh and someone reading the report will not select the enable option. I need to rethink my entire approach to this project now.

Hi,

I have added your comment in the related issue. We will update you asap.

Hi,

We support calculating pivot table with calculated fields in it in the latest fixed version(attached), please try it.

Thank you.