How to remove trailing blank rows / columns

I am using Microsoft Interop to convert excel files to csv files. I am using the sheet.SaveAs function.

My original excel sheet has data from columns A1 to AZ for 100 rows. I need in CSV only data from A1 to AP and only for 50 lines.

Using the Range function, I delete line 51-100, I clear the contents for the same lines, but when I save the CSV, I find lines 51-100, as shown below: (just commas). I do not want to see these commas in CSV.

,,,,,,,,,,,,,,,,,,,,,,,,,

The same goes for the AQ-AZ column. I do not need this data in CSV. I delete, clear the contents using the Range function, but these AQ-AZ columns are displayed in CSV files as ",,,,,,,,,,,".

Is there a way to save XLS as CSV with the only range I want to see in the CSV file. Is there a way to control the range that goes into the CSV file?

In short, I want to see in the CSV file only the data for column A1 in AP for 50 rows. No empty trailing "," s. Is there any way?

+5
source share
3 answers

The problem you are describing seems to be the "last cell" problem. The last cell is the original end of your data even after deleting rows / columns.

Here's what Microsoft has to say about it: How to reset the last cell in Excel

I seem to remember a programmatic way to do this, but for life I don't remember how.

By looking at this information, perhaps you could rethink how you can do this.

, .

. , , ,     , string.join     .csv.

+3

, , , CSV.

+1

Excel, : . .

0

All Articles