/*
Microsoft SQL Server Integration Services Script Task
Write scripts using Microsoft Visual C# 2008.
The ScriptMain is the entry point class of the script.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.IO;
using System.Data.OleDb;
namespace ST_1feb807359714c80ae0bdd964110df59.csproj
{
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
#region VSTA generated code
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
/*
The execution engine calls this method when the task executes.
To access the object model, use the Dts property. Connections, variables, events,
and logging features are available as members of the Dts property as shown in the following examples.
To reference a variable, call Dts.Variables["MyCaseSensitiveVariableName"].Value;
To post a log entry, call Dts.Log("This is my log text", 999, null);
To fire an event, call Dts.Events.FireInformation(99, "test", "hit the help message", "", 0, true);
To use the connections collection use something like the following:
ConnectionManager cm = Dts.Connections.Add("OLEDB");
cm.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorks;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;";
Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
To open Help, press F1.
*/
static void Main(string[] args)
{
string sourceFile, worksheetName, targetFile;
sourceFile = "C:\\NewFolder\\Sample.xls"; worksheetName = "sheet1"; targetFile = "C:\\NewFolder\\target.csv";
convertExcelToCSV(sourceFile, worksheetName, targetFile);
}
static void convertExcelToCSV(string sourceFile, string worksheetName, string targetFile)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sourceFile + ";Extended Properties=\" Excel.0;HDR=Yes;IMEX=1\"";
OleDbConnection conn = null;
StreamWriter wrtr = null;
OleDbCommand cmd = null;
OleDbDataAdapter da = null;
try
{
conn = new OleDbConnection(strConn);
conn.Open();
cmd = new OleDbCommand("SELECT * FROM [" + worksheetName + "$]", conn);
cmd.CommandType = CommandType.Text;
wrtr = new StreamWriter(targetFile);
da = new OleDbDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
for (int x = 0; x < dt.Rows.Count; x++)
{
string rowString = "";
for (int y = 0; y < dt.Columns.Count; y++)
{
rowString += "\"" + dt.Rows[x][y].ToString() + "\",";
}
wrtr.WriteLine(rowString);
}
Console.WriteLine();
Console.WriteLine("Done! Your " + sourceFile + " has been converted into " + targetFile + ".");
Console.WriteLine();
}
catch (Exception exc)
{
Console.WriteLine(exc.ToString());
Console.ReadLine();
}
finally
{
if (conn.State == ConnectionState.Open)
conn.Close();
conn.Dispose();
cmd.Dispose();
da.Dispose();
wrtr.Close();
wrtr.Dispose();
}
}
}
}
Ich verwende C# -Skript -Aufgabenkomponente, um XLs in eine CSV -Datei umzuwandeln. Mein Einstiegspunkt wird auf scriptMain < /p>
festgelegt, aber ich erhalte ständig Fehler.[code]/* Microsoft SQL Server Integration Services Script Task Write scripts using Microsoft Visual C# 2008. The ScriptMain is the entry point class of the script. */
using System; using System.Collections.Generic; using System.Text; using System.Data; using System.IO; using System.Data.OleDb;
namespace ST_1feb807359714c80ae0bdd964110df59.csproj { [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")] public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase {
/* The execution engine calls this method when the task executes. To access the object model, use the Dts property. Connections, variables, events, and logging features are available as members of the Dts property as shown in the following examples.
To reference a variable, call Dts.Variables["MyCaseSensitiveVariableName"].Value; To post a log entry, call Dts.Log("This is my log text", 999, null); To fire an event, call Dts.Events.FireInformation(99, "test", "hit the help message", "", 0, true);
To use the connections collection use something like the following: ConnectionManager cm = Dts.Connections.Add("OLEDB"); cm.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorks;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;";
Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
Guten Morgen. Ich versuche, eine XLS-Datei aus drei verschiedenen CSV-Dateien zu erstellen, die von Windows aus im Verzeichnis /temp abgelegt werden. Diese CSV-Dateien enthalten Daten aus einer...
Wir verwenden den folgenden Quellcode für eine Skriptaufgabe von SSIS, zielt auf .NET Framework v4.7 und die entsprechende C# -sprachversion V7.3.
Die Quelle sein Der Code kann jedoch erfolgreich...
net.Ich benutze JQuery, um einen Operation durchzuführen. Wenn ich meinen Code auf lokaler Bereitstellung bereitstellt, funktioniert er gut. Aber wenn ich meinen gleichen Code auf dem Live -Server...
Wir haben herausgefunden, dass wir zur Verwendung von Bibliotheken in der Skriptaufgabe von SSIS -Paketen die DLL zu GAC (globaler Assembly -Cache) manuell hinzufügen und eine Referenz in die DLL...
Ich versuche, 100 Bewertungen/Bewertungen in einem Yelp -Restaurant für eine Aufgabe mit BeautifulSoup zu kratzen. Ich suche speziell nach:
Bewertungskommentar
Bewertungs -ID
Bewertungsbewertung
Ich...