Code Monkey home page Code Monkey logo

Comments (3)

GoogleCodeExporter avatar GoogleCodeExporter commented on June 21, 2024

Original comment by jetcat on 12 Feb 2009 at 3:31

  • Changed state: Accepted
  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

from excellibrary.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 21, 2024

Original comment by jetcat on 12 Feb 2009 at 3:32

from excellibrary.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 21, 2024
Workbook book = Workbook.Load(filename);
                Worksheet sheet = book.Worksheets[0];
                if (sheet.Cells.Rows.Count > 0)
                {
                    DataTable tab = new DataTable();
                    Row HeadRow = sheet.Cells.GetRow(0);
                    DataColumn dc;

                    //把第一行当成列标题  the First Row is ColumName
                    for (int a = 0; a < HeadRow.LastColIndex; a++)
                    {
                        dc = new DataColumn(HeadRow.GetCell(a).StringValue);
                        tab.Columns.Add(dc);
                    }
                    for (int rowIndex = sheet.Cells.FirstRowIndex + 1; rowIndex <= sheet.Cells.LastRowIndex; rowIndex++)
                    {
                        DataRow dr = tab.NewRow();
                        Row row = sheet.Cells.GetRow(rowIndex);
                        for (int colIndex = row.FirstColIndex; colIndex <= row.LastColIndex; colIndex++)
                        {
                            //Can not use row.GetCell(colIndex).Format.FormatType 
                            if (HeadRow.GetCell(colIndex).StringValue.IndexOf("日期") >= 0)
                            {
                                Double df = double.Parse(row.GetCell(colIndex).StringValue);
                                DateTime dt= DateTime.FromOADate(df);
                                dr[colIndex] = dt.ToString("yyyy-MM-dd HH:mm:ss");
                            }

                            else { dr[colIndex] = row.GetCell(colIndex).StringValue; }
                        }
                        tab.Rows.Add(dr);
                    }
                    book = null;
                    sheet = null;
                    dgv.DataSource = tab;

Original comment by [email protected] on 15 Nov 2013 at 8:43

from excellibrary.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.