Article View: borland.public.cppbuilder.database.ado
Article #2880Re: Importing data form diferent tables and database types
From: Vladimir Afanasyev
Date: Mon, 24 Feb 2003 13:32
Date: Mon, 24 Feb 2003 13:32
65 lines
3084 bytes
3084 bytes
Hi Dmitry,
Dmitry <ivanov@iamm.ac.donetsk.ua> wrote:
>Vladimir, I need realize reverse problem: convert data from XLS file
>into any C++ Builder DataSet. Can you help me in this?
>Sincerely, Dmitry
>
The main problem it is how to find where data ends in the Excel.
If you will save data manually from Excel to dBase the Excel
ask you about boundary of data. It doesn't know where end
line and end column.
Another problem it is type of data. In DB the data is structured.
The data in the same field for every record has the same format.
But for Excel A1 can be number and A2 can be string.
I think that easiest way to solve your task it save data in the
csv (linear format with separators).
Separator: You can set separator by next Win32 API function:
bool result=SetLocaleInfo(
LOCALE_SYSTEM_DEFAULT, // locale identifier
LOCALE_SLIST, // type of information to set
"#" // pointer to information to set
);
In this sample: # - separator. You can find this
separator in the Control Panel -> Local Options
(or Language and Standards dependely from Windows language).
Converting .xls to .csv:
if(FileExists("c:\\1.csv"))DeleteFile("c:\\1.csv");
int csvType=6;
Variant covFalse((short)false);
Variant vExcel;
Function WorkbooksP("Workbooks");
Function OpenF("Open");
Variant WorkBooks;
Variant WorkBook;
Function SaveAsF("SaveAs");
Function CloseF("Close");
Function QuitF("Quit");
vExcel=Variant::CreateObject("Excel.Application");
//no need to do next command - it only do Excel visible on
//Screen
vExcel.Exec(PropertySet("Visible") << Variant((short)true));
WorkBooks=vExcel.Exec(WorkbooksP);
WorkBook=WorkBooks.Exec(OpenF << "c:\\1.xls");
WorkBook.Exec(SaveAsF << AnsiString("c:\\1.csv") << Variant(csvType));
WorkBook.Exec(CloseF << covFalse);
vExcel.Exec(QuitF);
How to create table in run time you can find in Borland's Help
for "TTable::CreateTable" method. There you can find example.
Best regards,
Vladimir.
Technical Details
Message-ID:
<3e5a1ee5$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3e4cf489$1@newsgroups.borland.com> <3e509cbe$1@newsgroups.borland.com> <3E5620B9.6030605@iamm.ac.donetsk.ua>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10698b,5718363b56ae1b18 X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2003-02-24 05:40:02 PST From: "Vladimir Afanasyev" <avv@systema.kiev.ua> Sender: "Vladimir Afanasyev" <avv@systema.kiev.ua> Reply-To: "Vladimir Afanasyev" <avv@systema.kiev.ua> Subject: Re: Importing data form diferent tables and database types Newsgroups: borland.public.cppbuilder.database.ado X-User-Info: 62.244.14.114 62.244.14.114 X-Forwarded-For: 192.168.0.147 References: <3e4cf489$1@newsgroups.borland.com> <3e509cbe$1@newsgroups.borland.com> <3E5620B9.6030605@iamm.ac.donetsk.ua> NNTP-Posting-Host: 207.105.83.65 Message-ID: <3e5a1ee5$1@newsgroups.borland.com> Date: 24 Feb 2003 05:32:21 -0800 X-Trace: newsgroups.borland.com 1046093541 207.105.83.65 (24 Feb 2003 05:32:21 -0800) Lines: 65 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail