write an excel cell with a specific format in c #?

0

When I write a file with this code automatically occupies a "general" format to write it, the problem is that if I want to write numbers that start with 0 this automatically omits, for example if I want to write 0123445 I will 12345 as I can write the cell with a specific format from c #

 Excel.Application archivoxlsx = new Microsoft.Office.Interop.Excel.Application(); 
        Excel.Workbook libro = archivoxlsx.Workbooks.Open("c:/Users/Edgar/Desktop/base/Libro1.xlsx", 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, true, 0, true, false, false);

        Excel.Worksheet hoja = (Excel.Worksheet)libro.Worksheets.get_Item("Hoja1");
        hoja.Cells[v,h] = cadena;



        libro.Save();
        libro.Close();
    
asked by Edgar Diaz 26.07.2016 в 03:56
source

1 answer

1

You could format the cell as text before assigning the value

Excel.Worksheet hoja = (Excel.Worksheet)libro.Worksheets.get_Item("Hoja1");

((Excel.Range)hoja.Cells[v,h]).NumberFormat = "@";
hoja.Cells[v,h] = cadena;

I understand that NumberFormat applies to a Range, but if you can do

hoja.Cells[v,h].NumberFormat = "@";

would also be valid

How to format an Excel file using C #

How can i change the text format of a Excel Cell using C #?

    
answered by 26.07.2016 / 07:57
source