Excel工作表我試圖使用EPPlus從List<string>
值保存到一個Excel工作表所以我寫了這個代碼:如何從一個列表<string>保存值使用EPPLus
private void button3_Click(object sender, EventArgs e)
{
int value = bdCleanList.Count()/Int32.Parse(textBox7.Text);
string bases_generadas = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bases_generadas");
var package = new ExcelPackage();
package.Workbook.Worksheets.Add("L1");
ExcelWorksheet worksheet = package.Workbook.Worksheets[1];
worksheet.Name = "L1";
int j = 2;
int col = 1;
for (int i = 1; i < bdCleanList.Count(); i++)
{
if (i%Int32.Parse(textBox7.Text) == 0)
{
package.Workbook.Worksheets.Add("L" + j);
worksheet = package.Workbook.Worksheets[j];
worksheet.Name = "L" + j;
j += 1;
worksheet.Cells[i, col].Value = bdCleanList[i];
}
else
{
worksheet.Cells[i, col].Value = bdCleanList[i];
}
}
Byte[] bin = package.GetAsByteArray();
File.WriteAllBytes(System.IO.Path.Combine(bases_generadas, "bases_generadas_" + DateTime.Now.Ticks.ToString() + DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss") + ".xlsx"), bin);
MessageBox.Show("Se generaron un total de " + value + " bases y puede encontrarlas en la siguiente ruta: " + System.IO.Path.Combine(bases_generadas, "bases_generadas_" + DateTime.Now.Ticks.ToString() + DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss") + ".xlsx"), "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
在樣本我跑bdCleanList.Count()
有2056個值,Int32.Parse(textBox7.Text)具有500作爲值,以便value
得到在這種情況下,這裏的問題是,L2,L3 ... L5值不保存,我不知道爲什麼。第一張工作表的值保存得很好,但其餘的都沒有,我的代碼出了什麼問題?如何設置活動工作表以便將活動工作表上的值保存起來?如何在工作表之間移動?
這是一個糟糕的標題。請閱讀http://meta.stackexchange.com/questions/10647/how-do-i-write-a-good-title – 2013-04-27 16:04:02
我不知道這是否是正確的,但只從看着這個我假設你需要' j.toString()' – Sayse 2013-04-27 16:05:46
@SonerGönül好些了嗎? – Reynier 2013-04-27 16:05:59