通过这些循环,它将信息发送到Excel。对于整组信息,它可能总共有6行到35行。每次在第二行和第三行信息之间插入一个空行。任何线索为什么?我想用“ - i”它会删除它可能尝试插入的末尾的任何空行。
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;
}
}