我有应该将excel模板表移动到新工作簿中的代码(见下文)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Excel;
namespace CodeCall
{
public class Excel
{
public static void Main()
{
ApplicationClass app = new ApplicationClass();
Workbook curWorkBook = null;
Workbook destWorkbook = null;
Worksheet workSheet = null;
Worksheet newWorksheet = null;
Object defaultArg = Type.Missing;
try
{
// Copy the source sheet
curWorkBook = app.Workbooks.Open("filepath1", defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg);
workSheet = (Worksheet)curWorkBook.Sheets[1];
workSheet.UsedRange.Copy(defaultArg);
// Paste on destination sheet
destWorkbook = app.Workbooks.Open("filepath2", defaultArg, false, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg);
newWorksheet = (Worksheet)destWorkbook.Worksheets.Add(defaultArg, defaultArg, 6, defaultArg);
newWorksheet.UsedRange._PasteSpecial(XlPasteType.xlPasteValues, XlPasteSpecialOperation.xlPasteSpecialOperationNone, false, false);
}
catch (Exception exc)
{
System.Windows.Forms.MessageBox.Show(exc.Message);
}
finally
{
if (curWorkBook != null)
{
curWorkBook.Save();
curWorkBook.Close(defaultArg, defaultArg, defaultArg);
}
if (destWorkbook != null)
{
destWorkbook.Save();
destWorkbook.Close(defaultArg, defaultArg, defaultArg);
}
}
app.Quit();
}
}
}
运行代码时,出现以下错误消息:
错误:无法加载脚本执行。
我已经尝试将脚本代码复制并粘贴到新任务中。
有什么想法吗?
答案 0 :(得分:0)
我能够解决它。
我需要将Script入口点添加到代码中
[SSISScriptTaskEntryPoint]//Attribute]
public partial class ScriptMain : VSTARTScriptObjectModelBase
删除“ Excel”公共课程
从“ Public Static Void Main()”中获取代码,将其粘贴到新的“脚本任务”模板中,并相应地更新名称空间以解决问题。