How do I remove extra whitespaces from all cells using spreadsheetlight and c#?

85 Views Asked by At

I'm using SpreadsheetLight library to read/write *.xlsx files. In some of my files there are a lot of cells which have extra whitespaces in them.

How do I remove them efficiently ?

Can something like below work and be efficient ?

        SLDocument sl1= new SLDocument(@"D:\sample.xlsx", "Sheet1");

        SLWorksheetStatistics st=sl1.GetWorksheetStatistics();

        for (int i = 2; i <= st.EndRowIndex; ++i)
        {
            for (int j = 1; j <= st.EndColumnIndex; ++j)
            {
                if (j==3 || j==5)
                {
                    Console.WriteLine(sl1.GetCellValueAsDateTime(i,j).ToString("dd-MM-yyyy").Trim());
                }

                else if (j==4)
                {
                    Console.WriteLine(sl1.GetCellValueAsDecimal(i,j).ToString("0.00").Trim());
                }

                else
                    Console.WriteLine(sl1.GetCellValueAsString(i,j).Trim());
            }
        }
0

There are 0 best solutions below