私はSQlから複数のストアドプロシージャを実行するコードを持っています。ただし、ストアドプロシージャからExcelファイルにデータを書き込む方法に問題があります。データをExcelファイルに書き込んだ後、Excelワークブックを保存します。どうすればこれを達成できますか?どんな助力も非常に感謝しています。Excelファイルにデータを書き込んで保存するには? EPPlus C#
これは私がこれまで持っているものです。
public static void ExecuteStoredProcedures()
{
using (SqlConnection connection = new SqlConnection("Data Source=the connection goes here.."))
{
SqlTransaction transaction;
connection.Open();
transaction = connection.BeginTransaction();
try
{
SqlCommand cmdOne = new SqlCommand("exec ", connection);
SqlCommand cmdTwo = new SqlCommand("exec", connection);
SqlCommand cmdThree = new SqlCommand("exec", connection);
cmdOne.ExecuteNonQuery();
cmdTwo.ExecuteNonQuery();
cmdThree.ExecuteNonQuery();
transaction.Commit();
}
catch (Exception ex)
{
transaction.Rollback();
connection.Close();
}
}
}
public static void SaveExcelFile()
{
string SheetLocation = ConfigurationManager.AppSettings["SheetLocation"];
if (!System.IO.Directory.Exists(SheetLocation))
{
System.IO.Directory.CreateDirectory(SheetLocation);
}
ExecuteStoredProcedures(); //Should I call the method to load the data that comes from the stored procedures? Or what should I do to write the data into the file?
var newFile = new FileInfo(@"C:\Users\");
using (ExcelPackage xlPackage = new ExcelPackage(newFile))
{
xlPackage.Save();
}
}
あなたはドキュメントを見ていました全く?あなたは何も試していないようです。 – mason
ドキュメントと例をお読みください。彼らはすでに何をすべきかを示しています。 EPPlusには、単一コールでExcelの範囲にデータをロードできるLoadCollection *および* LoadDataTableがあります。 –