Post a batch of xlsreadwriteii blog posts. Reference.

Source: Internet
Author: User
Tags dateformat

How to Use xlsreadwriteii to read Excel files in Delphi


Xlsreadwriteii v5.2020.1a for Delphi xe5 x32:

Http://download.csdn.net/detail/wozengcong/6878409

Xlsreadwriteii v5.10.25 cracked for XE2-XE4 (win32 ):
Http://download.csdn.net/detail/wozengcong/6886915


Xlsreadwriteii_v5.20.25, XE-XE6 〗:

Http://download.csdn.net/detail/wozengcong/7689003


Installation steps:
1. Click "component-> install packages" in the main menu of Embarcadero rad studio xe2 to add (ADD) xlsrwii5_dxe version. BPL
2. Click "toosl-> options-> Delphi options-> library-> library path" in the main menu of Embarcadero rad studio xe4 to add the full path of library path: OBJ and xlsreadwriteii respectively.

Installation steps:
1. Click "component-> install packages" in the main menu of Embarcadero rad studio xe2 to add (ADD) xlsrwii5_dxe2.bpl.
2. Click "toosl-> options-> Delphi options-> library-> library path" in the main menu of Embarcadero rad studio xe4 to add the library path:
Complete path of OBJ and xlsreadwriteii
Reading Excel files in Delphi is annoying when using createoleobject. It is always wrong. After the file is output, an Excel file will always be opened in the system, even quit won't work, there is a lot of use in a program, and there is no way to do anything. So I found xlsreadwriteii.

This is really good and easy to use. Both read and write operations are easy. Below is the code in the official demo.

Write File Code, including customization of the format:

[Delphi] view plaincopyprint? View the code piece derived from my code piece on code
XLS. filename: = 'formatsample.xls ';
XLS. Clear;
// Add format #0
With XLS. formats. Add do begin
Fontindex: = XLS. fonts. addindex;
XLS. fonts [fontindex]. Name: = 'courier new ';
XLS. fonts [fontindex]. Size: = 14;
XLS. fonts [fontindex]. Color: = xcred;
End;
// Add format #1
With XLS. formats. Add do begin
Fontindex: = XLS. fonts. addindex;
XLS. fonts [fontindex]. assigntfont (font );
End;
// Add format #2
With XLS. formats. Add do begin
Fillpatternforecolor: = xclilac;
End;
// Add format #3
With XLS. formats. Add do begin
Bordertopcolor: = xcblue;
Borderbottomcolor: = xcblue;
Bordertopstyle: = cbsthin;
Borderbottomstyle: = cbsthick;
End;
// Add format #4
// Required dateformat is a Delphi global variable for the local date format.
With XLS. formats. Add do begin
Numberformat: = Invalid dateformat;
End;
XLS. Sheets [0]. writestring (1, 2, 0, 'format #0 ');
XLS. Sheets [0]. writestring (1, 3, 1, 'format #1 ');
XLS. Sheets [0]. writestring (, 2, 'format #2 ');
XLS. Sheets [0]. writestring (1, 5, 3, 'format #3 ');
XLS. Sheets [0]. writenumber (1, 6, 4, date );
XLS. Write; // if you need to save it as a file, change filename and write it again. To change the workbook name, set sheet [0]. Name.

Read the file code:

[Delphi] view plaincopyprint? View the code piece derived from my code piece on code
VaR
Col, row: integer;
Sum: Double;
Begin
If edfilename. Text = ''then begin
Showmessage ('filename is missing ');
Exit;
End;
Sum: = 0;
XLS. filename: = edfilename. text;
XLS. Read; // This row cannot be saved; otherwise, data cannot be read.
XLS. Sheets [0]. lastcol: = 255;
XLS. Sheets [0]. lastrow: = 65535;
For Col: = XLS. Sheets [0]. firstcol to XLS. Sheets [0]. lastcol do begin
For row: = XLS. Sheets [0]. firstrow to XLS. Sheets [0]. lastrow do begin
If (row <grid. rowcount) and (COL <grid. colcount) then
Grid. cells [col + 1, row + 1]: = XLS. Sheets [0]. asfmtstring [col, row];
If XLS. Sheets [0]. celltype [col, row] = ctfloat then
Sum: = sum + XLS. Sheets [0]. asfloat [col, row];
End;
End;
Lblsum. Caption: = format ('the sum of all numeric cells are: %. 2f ', [Sum]);
Grid. invalidate;
End;

Tip:

Xe5 error solution:

1. [dcc32 Error] unit1.pas (51): e2003 undeclared identifier: 'ctfloat'

[Delphi] view plaincopyprint? View the code piece derived from my code piece on code
Uses xlssheetdata5, xlsreadwriteii5, xc12utils5; // Add reference: xc12utils5
Ctfloat to xctfloat


2. [dcc32 Error] unit1.pas (42): e2064 left side cannot be assigned

[Delphi] view plaincopyprint? View the code piece derived from my code piece on code
XLS. Sheets [0]. lastcol: = 255;
XLS. Sheets [0]. lastrow: = 65535;
Delete or comment out

3. Alias description:

XLS is the name of the xlsreadwriteii5 component, and grid is the name of the stringgrid component.

 

Post a batch of xlsreadwriteii blog posts. Reference.

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.