开发者

Adding a value to the end of a column in an array of strings to export to CSV

I am currently exporting data from an excel import using excel interop. I've been fiddling with this for a few hours now, but can't get the export as I desire.

I'm taking a range of 2 columns and about 1k rows from an excel doc, and simply want to add a comma to the end of each column, but because of the way that I'm looping through the range values, I can't seem to get my head around it. Anyway, here's the code:

for (long colCounter = 1; colCounter <= iCols; colCounter++)
{
    for (long rowCounter = 1; rowCounter <= iRows; rowCounter++)
    {
     开发者_如何学JAVA   //Write the next value into the string.
        valueString = 
            valueString.ConcatImport(Convert.ToString(saRet[rowCounter, colCounter]), "\n");
     }
}

I think I need to add another loop somewhere to check if I'm at a new column or not, and then add the comma value on. Similar to how its implemented for new lines in each row, but I just can't seem to get there!

Thanks for any help!


StringBuilder sb=new StringBuilder(); 
for (long rowCounter = 1; rowCounter <= iRows; rowCounter++)
 {
    for (long colCounter = 1; colCounter <= iCols; colCounter++)
    {
        sb.Append(Convert.ToString(saRet[rowCounter, colCounter]));
        sb.Append(",");       
     }
sb=sb.ToString().TrimEnd(',');
sb.Append("\n");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜