c# - Split string by length to Excel -
i sending , splitting long lines of data excel. each split prints in new row. want change splitting @ pipe symbol in existing data splitting @ character length of 85, , there chances @ character 85 may split word in two. how tell split further data if going split actual word. know if @ 85 should find space after. i'm curious on add.
// add description string descriptionsplit = srcaddonpanel.controls["txtproductdescaddon" + addrow].text; string[] descriptionparts = descriptionsplit.split('|'); int i; (i = 0; <= descriptionparts.getupperbound(0); i++) { worksheet.rows[currentrow].insert(); //applies description default bundle row worksheet.rows[currentrow].font.bold = false; worksheet.cells[currentrow, "e"].value = rowindent + descriptionparts[i].trim(); currentrow++; }
you use approach (warning not tested)
int x = 85; int y = 0; int currentrow = 0; // loop until have @ least 85 char grab while (x + y < descriptionsplit.length) { // find first white space after 85th char while (x + y < descriptionsplit.length && !char.iswhitespace(descriptionsplit[x+y])) x++; // grab substring , pass excel currentrow insertrowtoexcel(descriptionsplit.substring(y, x), currentrow); // prepare variables next loop currentrow++; y = y + x + 1; x = 85; } // not forget last block if(y < descriptionsplit.length) insertrowtoexcel(descriptionsplit.substring(y), currentrow); ... void insertrowtoexcel(string toinsert, int currentrow) { worksheet.rows[currentrow].insert(); worksheet.rows[currentrow].font.bold = false; worksheet.cells[currentrow, "e"].value = rowindent + toinsert.trim(); }
Comments
Post a Comment