Home > Software engineering >  Using VS2013 reading Excel
Using VS2013 reading Excel

Time:09-30

In using the Internet to find the class is always an error while reading when open the Excel file

Char * file, * getStr, * p;
CEexcelExport m_Excel;
Int m_Sheet, len; BOOL isLoad;


M_Excel. InitExcel ();
Len=WideCharToMultiByte (CP_UTF8, 0, the path, the path. The GetLength (), NULL, 0, NULL, NULL);
P=new char [len + 1];
WideCharToMultiByte (CP_UTF8, 0, the path, the path. The GetLength (), p, len, NULL, NULL);
P [len]='\ 0';
M_Excel. OpenExcelFile (p);
The last sentence is always an error function prototype is
BOOL CEexcelExport: : OpenExcelFile (const char * file_name)
{
//turn off
CloseExcelFile ();

//template file is used to establish the new document
Excel_books_. AttachDispatch (excel_application_. Get_Workbooks (), true);

LPDISPATCH lpDis=NULL;
lpDis=excel_books_. Add (COleVariant (LPCTSTR file_name));
If (lpDis)
{
Excel_work_book_. AttachDispatch (lpDis);
//get the Worksheets
Excel_sheets_. AttachDispatch (excel_work_book_. Get_Worksheets (), true);

//record open file name
Open_excel_file_=file_name;

Return TRUE;
}

return FALSE;
}

An error in the red place, always wrong path to the file C: \ User \ \ Document Jason
But the file path is not here,
Make a great god genuflect is begged point just a little, thank you!

CodePudding user response:

CodePudding user response:

The content of the breakpoint file_name values, the wrong path

CodePudding user response:

File_name which value is correct,,,

CodePudding user response:

Try simply libxl library reading excel at http://blog.csdn.net/sunnyloves/article/details/9996669

CodePudding user response:

M_Excel excel_books, are to ensure effective value to ADD, I wonder if you EXCEL normal boot

CodePudding user response:

Start file address is problematic, later found to be the problem of long pointer, after transformation is still an error, tracking and transmission in is correct, but will add an error on the C: \ Users \ Document \ write path, there is no file, I don't know where to add the address, and Excel is normal, can be normal use, use OFFICE 2013

CodePudding user response:

CodePudding user response:

Please answer

CodePudding user response:

The building Lord solved? I am also this case! Can't figure out where the wrong

CodePudding user response:

The same red sentences wrong, no solution!

CodePudding user response:

The Add method applied in the Workbooks objects,

New Workbook, new Workbook will become activity Workbook, returns the Workbook,

Expression. The Add (Template)

Expression required, the expression returns a Workbooks objects,

Template Variant type, optional, determine how to create workbook, if this parameter is to specify a string of existing Microsoft Excel file name and then create a new workbook will with the specified file as a Template, if this parameter is a constant, a new workbook will contain the specified type of single working table, as one of the following XlWBATemplate constants: xlWBATChart, xlWBATExcel4IntlMacroSheet, xlWBATExcel4MacroSheet or xlWBATWorksheet, if you omit this parameter, Microsoft Excel will create contains a certain number of blank worksheet in the workbook (the number set by SheetsInNewWorkbook attribute),

Description
If the Template parameter specifies the file, the file name can include paths,

CodePudding user response:

 'open this example Analysis. XLS workbook: 

Workbooks. Open "ANALYSIS. XLS"
  • Related