) Koogra-Excel File Reading Tool

Source: Internet
Author: User

Koogra is an open-source Excel reader on the. NET platform.ProgramYou can download it from the open-source community. You can use it to read Excel files without office. Although this program has stopped updating, it is still very useful. The following describes how to use it.
Download to the programSource codeCompile and generate net. SourceForge. koogra. dll. Reference this DLL in the project, using net. SourceForge. koogra. Excel;

Workbook WB = new Workbook (PATH); path is the physical path of the file, which can create an Excel file object
Worksheet xsheet = xbook. Sheets [0]; reference workbook Worksheet
Xbook. Sheets. getbyname (string) can also be used to obtain reference to the workbook worksheet.
Xbook. Sheets. Rows [I] References to excel rows
Xbook. Sheets. Rows [I]. cells [I] References to cells

The row number of the first line of xsheet. Rows. firstrow, starting from 0.
The row number of the end row of xsheet. Rows. lastrow. For empty rows in the middle, you can use xsheet. Rows [I] = NULL to judge
Cells also have the firstcol and lastcol attributes. If cells are null, cells. value cannot be used.

The following is an example:
/// <Summary>
/// This method just exercises the Excel Workbook data.
/// </Summary>
/// <Param name = "path"> the path to the workbook. </param>
Private workbook dumpworkbooktoconsole (string path)
{
// Print the path
Console. writeline (PATH );

// Construct our workbook
Workbook WB = new Workbook (PATH );

// Dump the worksheet data
Foreach (worksheet ws in WB. Sheets)
{
Console. Write ("sheet is ");
Console. Write (WS. Name );

Console. Write ("First row is :");
Console. Write (WS. Rows. firstrow );

Console. Write ("Last Row is :");
Console. writeline (WS. Rows. lastrow );

// Dump cell data
For (INT r = ws. Rows. firstrow; r <= ws. Rows. lastrow; ++ R)
{
Row row = ws. Rows [(ushort) R];

If (row! = NULL)
{
Console. Write ("row :");
Console. Write (R );

Console. Write ("first Col :");
Console. Write (row. cells. firstcol );

Console. Write ("Last Col :");
Console. writeline (row. cells. lastcol );

For (INT c = row. cells. firstcol; C <= row. cells. lastcol; ++ C)
{
Cell cell = row. cells [(byte) C];

Console. Write ("Col :");
Console. Write (C );

If (cell! = NULL)
{
Console. Write ("value :");
Console. Write (cell. value );
Console. Write ("formatted value :");
Console. writeline (cell. formattedvalue ());
}
Else
Console. writeline ("null ");
}
}
}
}

Return WB;
}
More functions are to be explored ~ It is written in C #, SourceCodeAlso, take a look. In addition, another open-source Dongdong: myxls supports Excel reading and writing, and is still being updated, which is also very good.

Some amendments to koogra:
1. Fixed the bug of garbled Chinese worksheet names
\ Excel \ records \ boundsheetrecord. CS 34 ~ 38 rows

Ushort namelen = reader. readuint16 ();
Stringbuilder NB = new stringbuilder (namelen );
NB. append (new string (reader. readchars (namelen )));

_ Name = Nb. tostring ();

Change

Ushort namelen = (ushort) reader. readbyte ();
Bool compressed = (reader. readbyte () * 0x01) = 0;

If (! Compressed ){
Namelen * = 2;
}

Byte [] charbytes = reader. readbytes (namelen );

If (Compressed ){
// Decompress
Byte [] widebytes = new byte [charbytes. length * 2];
For (INT I = 0; I <charbytes. length; I ++)
Widebytes [2 * I] = charbytes [I];
Charbytes = widebytes;
}

_ Name = new string (encoding. Unicode. getchars (charbytes ));

2. Adjust the default format of the date
Obtain the date data of the Excel worksheet, for example
Cell. formattedvalue () is used to obtain the string "3/5/07"
This is usually not what I want, so I modified the original cell. CS
Public String formattedvalue (){
...
...
// Get the Format String
String formatstring = format. formatvalue;
+ If (formatstring = "m/D/YY "){
+ Formatstring = "yyyy/mm/DD ";
+}
----------------- For bloger -------------------
Today, we found that koogra has been updated to version 3.1.1. Only DLL files are supported. However, you can use reflector.Decompile the source code.
Project address:Koogra

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.