C# 带Excel插入的空行
通过这些循环,它将信息发送到Excel。对于整个信息组,它可能总共有6到35行。每次它都会在第二行和第三行信息之间插入一个空行。有什么线索说明原因吗?。我认为使用“-I”可以删除结尾处可能尝试插入的任何空行C# 带Excel插入的空行,c#,C#,通过这些循环,它将信息发送到Excel。对于整个信息组,它可能总共有6到35行。每次它都会在第二行和第三行信息之间插入一个空行。有什么线索说明原因吗?。我认为使用“-I”可以删除结尾处可能尝试插入的任何空行 for (BndlRow = 0; BndlRow < bundleRows; BndlRow++) { if (((System.Windows.Forms.TextBox)srcBundlePanel.Controls["txtQtyBun
for (BndlRow = 0; BndlRow < bundleRows; BndlRow++)
{
if (((System.Windows.Forms.TextBox)srcBundlePanel.Controls["txtQtyBundle" + BndlRow]).Text != "0" &&
((ComboBox)srcBundlePanel.Controls["cboPaystructureBundle" + BndlRow]).Text.ToString() == "Nonrecurring")
{
// worksheet.Rows[currentRow + BndlRow].Insert();
worksheet.Rows[currentRow + newRow].Insert();
worksheet.Rows[currentRow + newRow].Font.Size = 14;
worksheet.Rows[currentRow + newRow].Font.Bold = false;
worksheet.Cells[currentRow + newRow, "E"].Font.Bold = true;
worksheet.Rows[currentRow + newRow].Interior.Color = CyberaWhite;
worksheet.Columns["A"].Interior.Color = CyberaGrey;
worksheet.Columns["J:XFD"].Interior.Color = CyberaGrey;
worksheet.Cells[currentRow + newRow, "C"].Interior.Color = CyberaPurple;
worksheet.Rows[currentRow + newRow].HorizontalAlignment = XlHAlign.xlHAlignLeft;
worksheet.Cells[currentRow + newRow, "D"].HorizontalAlignment = XlHAlign.xlHAlignCenter;
worksheet.Cells[currentRow + newRow, "D"].value = srcBundlePanel.Controls["txtQtyBundle" + BndlRow].Text;
worksheet.Cells[currentRow + newRow, "E"].value = srcBundlePanel.Controls["txtProductNameBundle" + BndlRow].Text;
worksheet.Cells[currentRow + newRow, "F"].value = srcBundlePanel.Controls["txtListPriceBundle" + BndlRow].Text;
worksheet.Cells[currentRow + newRow, "G"].value = srcBundlePanel.Controls["txtMaxDiscountBundle" + BndlRow].Text;
worksheet.Cells[currentRow + newRow, "H"].value = srcBundlePanel.Controls["txtProposedPriceBundle" + BndlRow].Text.Replace("I", "Included").Replace("EV", "Evaluation").Replace("EX", "Existing"); //REPLACES** // Increment the counter so we track how many lines we actually added.
newRow++;
string DescriptionSplit = srcBundlePanel.Controls["txtProductDescBundle" + BndlRow].Text;
string[] descriptionParts = DescriptionSplit.Split('|');
int i;
for (i = 0; i < descriptionParts.Length; i++)
{
worksheet.Rows[currentRow + newRow + i].Insert(); //applies the description for the default bundle row
worksheet.Rows[currentRow + newRow + i].Font.Bold = false;
worksheet.Cells[currentRow + newRow + i, "E"].Value = rowIndent + descriptionParts[i].Trim();
}
currentRow += newRow + --i;
}
}
for(BndlRow=0;BndlRow
您可以在bundleRows上使用foreach()。您是说用foreach替换for吗?不成功是,用最简单的话来说。您也可以使用LINQ在对象之间循环,但是foreach(){}将确保您只处理这些对象,而不会超出边界。由于加载每个对象,foreach()的速度稍微慢了一点,但是在上面的示例中不应该注意到这一点。