I have a previous question similar to this but I am still frozen on the actual solution. I am sending rows of text from dynamic textboxes to Excel, this information comes from a database. Within the rows I am sending "txtProductNameBundle" and on occasion a "product description"("txtProductDesc") row that will have to split and would need to be in place under the "txtProductNameBundle" in Excel, it could be 1 row or up to 6. I have my for loops that successfully send all of the rows (without Product Description) exactly where I need them. Here is the problem, I know how to perform a "split string" with the "txtProductDesc" as this text can be rather long and even send it to Excel but I am clueless on how to add a loop to place it after the "product name". The Excel sheet is a template so rows have to be inserted for as many rows of information that will be sent.
int StartBundleRow = 11; // row 11 is where I start to insert the dynamic controls
string rowIndent = " "; // adds spaces to the beginning of the text
string DescriptionSplit = frmProposal.ProdDesc.Text;
for (int BndlRow = 0; BndlRow < bundleRows; BndlRow++)
{
worksheet.Rows[StartBundleRow].Insert();
worksheet.Rows[StartBundleRow].Font.Size = 14; //********Excel formatting*********
worksheet.Cells[StartBundleRow, "E"].Font.Bold = true;
worksheet.Rows[StartBundleRow].Interior.Color = ColorTranslator.ToOle(Color.White);
worksheet.Columns["A"].Interior.Color = ColorTranslator.ToOle((Color)cc.ConvertFromString("#808080"));
worksheet.Columns["J:XFD"].Interior.Color = ColorTranslator.ToOle((Color)cc.ConvertFromString("#808080"));
worksheet.Rows[StartBundleRow].HorizontalAlignment = XlHAlign.xlHAlignLeft;
worksheet.Cells[StartBundleRow, "C"].Interior.Color = ColorTranslator.ToOle((Color)cc.ConvertFromString("#49176D"));
worksheet.Cells[StartBundleRow, "D"].value = srcBundlePanel.Controls["txtQtyBundle" + BndlRow].Text;
//(product name below)
worksheet.Cells[StartBundleRow, "E"].value = srcBundlePanel.Controls["txtProductNameBundle" + BndlRow].Text;
//(this is where I need to insert the split string of product description)
worksheet.Cells[StartBundleRow, "F"].value = srcBundlePanel.Controls["txtListPriceBundle" + BndlRow].Text;
worksheet.Cells[StartBundleRow, "G"].value = srcBundlePanel.Controls["txtMaxDiscountBundle" + BndlRow].Text;
worksheet.Cells[StartBundleRow++,"H"].value = srcBundlePanel.Controls["txtProposedPriceBundle" + BndlRow].Text;
}
** BELOW IS MY SAMPLE STAND ALONE CODE FOR SPLITTING THE STRING INTO 3 ROWS **
worksheet.Cells[11, "E"].Value = rowIndent + DescriptionSplit.Substring(0, DescriptionSplit.IndexOf("|")).Trim();
worksheet.Cells[12, "E"].Value = rowIndent + DescriptionSplit.Substring(DescriptionSplit.IndexOf("|") + 1,
DescriptionSplit.IndexOf("|")).Trim();
worksheet.Cells[13, "E"].Value = rowIndent + DescriptionSplit.Substring(DescriptionSplit.LastIndexOf("|") + 1,
DescriptionSplit.Length - DescriptionSplit.LastIndexOf("|") - 1).Trim();