开发者

ExtremeML Negative Exponent Export Issue

In C# I have a DataTable which has valid values, some of which are in exponential format. I export this DataTable to an xlsx file using ExtremeML (w开发者_如何学JAVAhich I believe is based on OpenXML) and the following code:

if (!Directory.Exists(savePath.Text))
        Directory.CreateDirectory(savePath.Text);

    using (var package = SpreadsheetDocumentWrapper.Create(savePath.Text + fileName + ".xlsx"))
    {
        for (int i = 0; i < dataset.Tables.Count; i++)
        {
            // declares worksheet
            var part = package.WorkbookPart.WorksheetParts.Add(dataset.Tables[i].TableName.ToString()); // second worksheet filled by second collection 

            bool first = true;
            int position = 0;
            for (int row = 0; row < dataset.Tables[i].Rows.Count; row++)
            {
                for (int col = 0; col < dataset.Tables[i].Columns.Count; col++)
                {
                    // adds to file 
                    if (first)
                        part.Worksheet.SetCellValue(new GridReference(row, col), dataset.Tables[i].Columns[col].ColumnName.ToString());
                    else
                        part.Worksheet.SetCellValue(new GridReference(row, col), dataset.Tables[i].Rows[position][col]);
                }
                if (first)
                {
                    first = false;
                }
                else
                    position++;
            }
        }
    }

The resulting excel file is almost acceptable, except that negative exponential negative numbers (for example -7.45E-05) treat the negative sign as a digit (previous example becomes 0.000-745). The columns are all set to be doubles in the DataTable, so the excel file should be formatting them as such.

Any ideas as to the cause of this problem? (Also, I know the code is a touch painful to grok- the code is not mine, and I haven't gotten around to cleaning up the program.)


Your sample code seems fine.

This looks like a bug in the way way ExtremeML converts doubles. As you say, it only appears to affect negative exponential negative numbers.

I am currently debugging it and creating additional unit tests to cover these scenarios, after which I will commit the updated code to CodePlex and post an update here.

Edit: This bug has now been fixed. You'll need to download and build the ExtremeML source code from CodePlex, as the runtime release is not currently up-to-date.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜