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

When a particular .xlsx file is read, strings are ok but numbers are all zero. #66

Open
robertrackl opened this issue Dec 28, 2021 · 0 comments

Comments

@robertrackl
Copy link

Puget+Sound+Soaring+Association_Balance+Sheet (4).xlsx

When reading the above file with FastExcel, cells with string contents behave as expected, whereas cells with numeric contents return zero. In the original file, only some cells have zero contents; most of them have non-zero numbers. So far, I have noticed this problem only with the attached file; FastExcel handles other .xlsx files properly. Here is what the beginning of the file looks like when opened with Microsoft Excel:
FewZeroes
Here is what the beginning of the file looks like after processing with the code shown later below:
AllZeroes

To demonstrate the problem, I use this C# code in file FastExcelRead.aspx.cs belonging to an ASP.Net web page:

using FastExcel;
using System;
using System.Data;
using System.IO;

namespace TSoar.Developer.SWLab
{
    public partial class FastExcelRead : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e){
            if (!IsPostBack)
            {   string sPath = Server.MapPath("~/AppData/ClubFinStat/Historical/2021-11-24/");
                DirectoryInfo di = new DirectoryInfo(sPath);
                FileInfo[] files = di.GetFiles("Puget+Sound+Soaring+Association_Balance+Sheet*.xlsx", 0);
                DataTable dt = new DataTable();
                int iNumCols = 0;
                using (FastExcel.FastExcel fEx = new FastExcel.FastExcel(files[0], true))
                {   Worksheet ws = fEx.Read(1); // There is only one worksheet
                    foreach (FastExcel.Row r in ws.Rows){
                        foreach (var cell in r.Cells)
                        {    iNumCols++; }
                        break;
                    }
                    for (int j = 0; j < iNumCols; j++)
                    {   dt.Columns.Add("Column " + (101 + j).ToString().Substring(1));
                    }
                    foreach (FastExcel.Row r in ws.Rows)
                    {   DataRow dr = dt.NewRow();
                        int j = 0;
                        foreach (var cell in r.Cells)
                        {   dr[j++] = cell.Value;
                        }
                        dt.Rows.Add(dr);
                    }
                }
                gv.DataSource = dt;
                gv.DataBind();
            }
        }
    }
}

Here is the code in the corresponding FastExcelRead.aspx file:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FastExcelRead.aspx.cs" Inherits="TSoar.Developer.SWLab.FastExcelRead" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Demo of FastExcel Reading all Numbers as Zeroes</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:GridView ID="gv" runat="server" AutoGenerateColumns="true"></asp:GridView>
        </div>
    </form>
</body>
</html>

It is always possible that I am doing something wrong in using the FastExcel package, but I kind of doubt it. A similar problem occurred with this particular .xlsx file when I processed it with ExcelDataReader.DataSet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant