Converting excel files with .xls or .xlsx extension to .csv add extra lines at the end

@gauti0710,

See the sample lines of code that you may try for your needs:
e.g
Sample code:

........
TxtSaveOptions options = new TxtSaveOptions(SaveFormat.CSV);
options.Separator = Convert.ToChar("|"); 
// Save the workbook in output CSV format.
workbook.Save(dirPath + "XLStocsv_Dummy.csv", options);

Hope, this helps a bit.

Its working Thanks a lot… :smile:

@gauti0710,

Good to know that the suggested code segment figures out your issue now. Feel free to contact us any time if you need further help or have some issue or queries, we will be happy to assist you soon.

Hi Team ,

I am back with another doubt

this time in file the address is like below

“UNILEVER HOUSE,B.D.SAWANT MARG,
CHAKALA,ANDHERI EAST
MUMBAI- 400099”

t
there is more space in between

i used the below code but i think that is for one space.

for (int iRow = 12; iRow < 68; iRow++)
{
var StringValue = workbook.Worksheets[0].Cells[iRow, 15].StringValue;
StringValue = StringValue.Replace(’\n’, ’ ');
workbook.Worksheets[0].Cells[iRow,15].Value = StringValue;
}

Can you please help how can i get rid of this

image.png (2.0 KB)

Please check image

@gauti0710,

You may try to use Trim() method to remove white spaces in the string, see the sample code for your reference:
e.g
Sample code:

for (int iRow = 12; iRow < 68; iRow++)
{
var StringValue = workbook.Worksheets[0].Cells[iRow, 15].StringValue;
StringValue = StringValue.Replace(’\n’, ’ ');
var newStringValue = StringValue.Trim();
workbook.Worksheets[0].Cells[iRow,15].Value = newStringValue;
}

Still i am getting double quotes for that particular row

@gauti0710,

Which double quotes you are talking about, please elaborate?

image.png (7.2 KB)
See for the uniliver row i am getting in double quotes

While for other rows it is normal So when i am performing other manipulations for this row i am getting error and the data for this going in next row

@gauti0710,

You mean those leading 15/16 spaces “CHAKALA” word in the string as per the screenshot and you want to remove it?

Yes i guess because of that the whole cell is coming in double quote

@gauti0710,

The better way to do it is replace all (bigger) spaces (which are more then two) with single space. You should devise your own way and write your own code to explore it further if it still does not fulfill your needs. Your requirements is beyond the scope of Aspose.Cells APIs. Anyways, see the following updated sample code for your reference:
e.g
Sample code:

//remove more than two spaces with single space (it will work for your needs) via regular expressions. 
for (int iRow = 12; iRow < 68; iRow++)
{
var StringValue = workbook.Worksheets[0].Cells[iRow, 15].StringValue;
StringValue = StringValue.Replace(’\n’, ’ ');
StringValue = Regex.Replace(StringValue, @"\s+", " ");
workbook.Worksheets[0].Cells[iRow,15].Value = StringValue;
}

Hope, this helps a bit.

Thanks I checked this is also not working i will try other things.

Last question
Can you please forward me the code for aspose to delete whole column

@gauti0710,

See the document with example on how to remove the column in the worksheet:

Please note, the line of code will delete the E column:
worksheet.Cells.DeleteColumn(4);

Sorry again i encountered one issue

actually i am running code using batch file like below

“E:\Process\Cash_Recon_Asia\Macro\Flatten_Excel_NEFT_INWARD\Flatten_Excel_NEFT_INWARD\bin\Debug\Flatten_Excel_NEFT_INWARD.exe”

but now i can see we receive multiple files, So to convert multiple files can we add the input file name and output after the command and put something in code to pick?

@gauti0710,
You may please follow the following article to use command line arguments: