There is a DLL: CSV2XLS_D.DLL
The DLL can convert CSV files to XLS and XLSX format
There are only two functions:
int
CSVtoXLS_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
CSVtoXLS_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.csv | Source CSV file |
Drive:\Path\FileName.xls | Target XLS file |
Drive:\Path\ | Target XLS folder |
/RECORDS=0 | Do not export records of the table. |
/OVERWRITE=1 | Overwrite existing file. |
/OVERWRITE=0 | Do not overwrite existing file. (default) |
/OVERWRITETABLE=1 | Overwrite existing table/sheet. (default) |
/OVERWRITETABLE=0 | Do not overwrite existing table/sheet. |
/SOURCE=ANSI | |
/SOURCE=OEM | Encoding of the source file. |
/TYPE=ANY | Convert to Excel 97-2003 & 5.0/95 (*.xls) |
/TYPE=2007 | Convert to Excel 2007-2010 (*.xlsx) |
/AUTODATE /MM.DD.YYYY /DD.MM.YYYY /YYYY.MM.DD | Date format, autodetect or user-defined |
/FIELDS=? Example: /FIELDS=; Special values: TAB means Tab (0x09) character. PIPE means | character. | Delimiter between fields. |
/ALLCHAR=1 | All fields will be converted as a string. |
/ALLCHAR=0 | The program will try to detect types of converted values,
such as Date, Logical, Numeric. There are two parameters that help the program to know what symbols are acceptable in Bollean and Numeric fields. |
////////////////////// sample1.cpp //////////////////////////// //parameters in the command line // //sample1.exe source.csv target.xls // #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("csv2xls_d.dll"); if (!h) retval = 200; else { f = (Converter)GetProcAddress(h, "CSVtoXLS_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.csv"); params[n++]=strdup("c:\\tmp\\"); params[n++]=strdup("/type=2007"); params[n++]=strdup("/overwrite=1"); h = LoadLibrary("csv2xls_d.dll"); if (!h) retval = 200; else { f = (Converter)GetProcAddress(h, "CSVtoXLS_Converter"); if (!f) retval = 300; else retval = f(NULL, n, params); } FreeLibrary(h); printf("ret = %d\n", retval); return retval; } // ////////////////////// sample2.cpp //////////////////////////// |