[英]SSIS to Excel - Excel Formulas not running automatically?
I have an SSIS package I created that currently has the following steps:我创建了一个 SSIS 包,目前有以下步骤:
1 - File System Task - Copy an Excel File (.xlsx) to use as a template for the output of the SSIS package. 1 - 文件系统任务 - 复制 Excel 文件 (.xlsx) 以用作 SSIS 包输出的模板。 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.
Excel 文件有 3 个选项卡 - 其中一个没有数据,但具有引用第二个和第三个选项卡上的值的公式。 This is the page the End User looks at (let's call it end_user).
这是最终用户查看的页面(我们称之为 end_user)。
2 - Data Flow Task - OLEDB Source -> Data Conversion -> Excel Destination (Tab 2, lets call this raw_data). 2 - 数据流任务 - OLEDB 源 -> 数据转换 -> Excel 目标(选项卡 2,我们称之为 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. 3 - 电子邮件任务 - 尚未实施,但将在产品的最后阶段出现,以使其完全自动化。
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.包运行完成后,我打开 Excel 文件,数据已写入 raw_data,但 end_user 上没有任何显示。 Here is what I have already tried, to resolve this in Excel:
这是我已经尝试过的,以在 Excel 中解决此问题:
Creating an Excel macro to force formula updates at the time the file is opened.创建 Excel 宏以在打开文件时强制更新公式。
Private Sub Workbook_Open() Application.Calculation = xlCalculationAutomatic End Sub
Running a Repair on Office.在 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.虽然Ctrl + Alt + F9选项使文件按预期显示,但它不是一个可接受的解决方案,因为我们都知道最终用户希望一切都完美运行。 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.
所以即使这个问题已经超过 3 年了,我还是希望我的解决方案可以帮助其他人。
I created a Script Task, with the following C# code (You'll need only to edit TheNameOfYourExcelConnection.xls).我创建了一个脚本任务,使用以下 C# 代码(您只需要编辑 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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.