I have an SSIS package I created that currently has the following steps:
1 - File System Task - Copy an Excel File (.xlsx) to use as a template for the output of the SSIS package. The Excel file has 3 tabs - one that has no data in it, but has formulas that reference values on the second and third tabs. This is the page the End User looks at (let's call it end_user).
2 - Data Flow Task - OLEDB Source -> Data Conversion -> Excel Destination (Tab 2, lets call this raw_data).
3 - Email Task - Hasn't been implemented yet, but will be here at the final stage of the product, to make this fully automated.
Upon the package finishing being run, I open the Excel file and the data has been written to raw_data, but nothing shows up on end_user. Here is what I have already tried, to resolve this in Excel:
Creating an Excel macro to force formula updates at the time the file is opened.
Private Sub Workbook_Open() Application.Calculation = xlCalculationAutomatic End Sub
Running a Repair on Office.
While the Ctrl + Alt + F9 option makes the file display as intended, it is not an acceptable solution, as we all know how end users want everything to work perfectly. Does anyone have any suggestions, experience with this happening, or any other insight? Anything helpful is greatly appreciated!
I had an identical situation. So even though this question is over 3 years old, I'm hoping my solution may help others down the line.
I created a Script Task, with the following C# code (You'll need only to edit TheNameOfYourExcelConnection.xls).
The script will connect to the spreadsheet, iterate over every cell in every sheet, and replace every occurrence of "=" with itself. In effect not changing the formulae, but forcing them to be recalculated.
#region Namespaces
using System;
using Microsoft.SqlServer.Dts.Runtime;
//add reference C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Excel\15.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.dll
using Excel = Microsoft.Office.Interop.Excel;
#endregion
namespace ST_10cafd32acda4eb1b677ebbdd2eb1286
{
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
public void Main()
{
Excel.Application excelApp = new Excel.Application();
ConnectionManager cm = Dts.Connections["TheNameOfYourExcelConnection.xls"];
string filepath = cm.Properties["ExcelFilePath"].GetValue(cm).ToString();
excelApp.DisplayAlerts = false;
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(filepath, 1, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, null, false);
try
{
Excel.Sheets excelWorkSheet = excelWorkbook.Sheets;
foreach (Excel.Worksheet work in excelWorkSheet)
{
work.Cells.Replace("=", "=");
}
excelWorkbook.Save();
excelWorkbook.Close();
}
catch (Exception ex)
{
}
finally
{
excelApp.Quit();
}
Dts.TaskResult = (int)ScriptResults.Success;
}
#region ScriptResults declaration
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.