C # format of a cell in excel

1

I need to open an excel file xlsx to remove the commas from a pair of tables so that I can convert the file to .csv . I want to know if I can do this with a NumberFormat or something similar? I'm starting from row 15, that's where the information starts to unfold

Up to this point I can change the cell formats, but I can not make them stay in the excel sheet. This is what I have:

Application excel = new Application();
Workbook sheet = excel.Workbooks.Open(filePatht);
Worksheet x = excel.ActiveSheet as Worksheet;
_Worksheet xlWorksheet = sheet.Sheets[1];
Excel.Range xlRange = xlWorksheet.UsedRange;
int rowCount = xlRange.Rows.Count;

for (int ix = 15; ix < rowCount; ix++) {
     var x18 = xlRange.Cells[ix, 8].Text;
     var x19 = xlRange.Cells[ix, 9].Text;
      xlRange.Cells[ix, 8].NumberFormat = "0.00";
      xlRange.Cells[ix, 9].NumberFormat = "0.00";
}

sheet.Close(true);
excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(x);
System.Runtime.InteropServices.Marshal.ReleaseComObject(sheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);

    
asked by E.Rawrdríguez.Ophanim 28.08.2018 в 00:31
source

1 answer

3

The problem is that the cell has a format so you see a formatted value (commas, points, currency symbols) but the value you have to deal with is not formatted, so you can not use the function replace. First you have to remove the format of the cell or cells, with NumberFormat="0", save the document and treat the value you have that you want.

Personally, the points do not matter to me, I'm more happy to contribute to solve a problem, especially when one is stuck and does not know where to look. Greetings

    
answered by 28.08.2018 / 21:21
source