There is a DLL: XLS2CSV_D.DLL
The DLL can convert XLS/XLSX files to CSV format
There are only two functions:
int
XLStoCSV_Converter(HWND hwnd, int argc, char *argv[]);
It accepts three parameters.
The first "hwnd" must be NULL. It is not used.
The second "argc" must be equal to number of parameters.
The third "argv" contains parameters.
int
XLStoCSV_ConverterStr(HWND hwnd, char *params);
It accepts two parameters.
The first "hwnd" must be NULL. It is not used.
The second "params" contains parameters which are delimited by #.
The functions return:
0 - success
1 - not recognized a source file
2 - not recognized a target folder or a target file
3 - cannot open a source file
| Drive:\Path\FileName.xls | Source XLS file |
| Drive:\Path\FileName.csv | Target CSV file |
| Drive:\Path\ | Target CSV folder |
| /RECORDS=0 | Do not export records of the table. |
| /OVERWRITE=1 | Overwrite existing file. |
| /OVERWRITE=0 | Do not overwrite existing file. (default) |
| /REMCRLF=1 | Remove CR+LF in Memo fields. |
| /REMCRLF=0 | Do not remove CR+LF in Memo fields. |
| /ESCAPE=????? | Escape character before a single or a double quote. Examples: /ESCAPE=# "/ESCAPE="" |
| /QUOTES=1 | Conclude character and memo fields in double quotes. |
| /QUOTES=0 | Do not conclude character and memo fields in double quotes. |
| /FIELDS=? | Delimiter between fields. Example: /FIELDS=;
Special values: |
| /RECORDS=? | Delimiter between records. Example: /FIELDS=CRLF
Special values: |
| /HEADER=1 | Include fields names. |
| /HEADER=0 | Do not include field names. |
////////////////////// sample1.cpp ////////////////////////////
//parameters in the command line
//
//sample1.exe source.xls target.csv
//
#include <windows.h<
#include <stdio.h>
typedef int (APIENTRY *Converter)(HWND, UINT, CHAR**);
int main(int argc, char* argv[])
{
int retval;
HMODULE h;
Converter f;
h = LoadLibrary("xls2csv_d.dll");
if (!h) retval = 200;
else
{
f = (Converter)GetProcAddress(h, "XLStoCSV_Converter");
if (!f) retval = 300;
else retval = f(NULL, argc, argv);
}
FreeLibrary(h);
printf("ret = %d\n", retval);
return retval;
}
//
////////////////////// sample1.cpp ////////////////////////////
|
|
////////////////////// sample2.cpp ////////////////////////////
//parameters in the source code
//
//sample2.exe
//
#include <windows.h>
#include <stdio.h>
typedef int (APIENTRY *Converter)(HWND, UINT, CHAR**);
int main(int argc, char* argv[])
{
int retval;
HMODULE h;
Converter f;
int n=0;
char *params[10];
params[n++]=strdup(__argv[0]);
params[n++]=strdup("source.xls");
params[n++]=strdup("c:\\tmp\\");
params[n++]=strdup("/overwrite=1");
h = LoadLibrary("xls2csv_d.dll");
if (!h) retval = 200;
else
{
f = (Converter)GetProcAddress(h, "XLStoCSV_Converter");
if (!f) retval = 300;
else retval = f(NULL, n, params);
}
FreeLibrary(h);
printf("ret = %d\n", retval);
return retval;
}
//
////////////////////// sample2.cpp ////////////////////////////
|