Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Number format is not correctly converted when using XLRange.AsTable().AsNativeDataTable() #1242

Open
1 task done
parag-patil opened this issue Jul 1, 2019 · 1 comment
Labels

Comments

@parag-patil
Copy link

  • Bug

Version of ClosedXML
0.94.2.0

Presently, Excel's CellFormat = Number is not converting correctly using XLRange.AsTable().AsNativeDataTable().

My excel has column with the cellFormat as Number with 0 decimal places. But whenever I use above statement to read the excel into DataTable, it convert that column into Double data type and shows data with one decimal place.

What is the expected behavior or new feature?

Expected behavior is system it should read as Number with 0 decimal places.

Did this work in previous versions of our tool? Which versions?

NO

Code to reproduce problem:

var workBook = GetXLWorkbook(_postedData.File);
            var workSheet = workBook.Worksheets.FirstOrDefault();
            var firstDetailRowAddress = workSheet.Row(_postedData.DetailLineNumber).FirstCell().Address;
            var lastDetailRowAddress = workSheet.LastCellUsed().Address;
            var detailTableRange = workSheet.Range(firstDetailRowAddress, lastDetailRowAddress).RangeUsed();
            var detailTable = detailTableRange.AsTable().AsNativeDataTable();

            var _jsonSettings = new JsonSerializerSettings();
            _jsonSettings.DateFormatString = "MM/dd/yyyy hh:mm:ss tt";
            return JsonConvert.SerializeObject(detailTable, _jsonSettings);

Reproduce - Upload excel with column with cellFormat as Number with 0 decimal places.

@igitur
Copy link
Member

igitur commented Jul 5, 2019

Give me code that I can run, please.

@igitur igitur added the RTFM label Jul 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants