How can I modify the date format in EXCEL with VBA?
Solved
General and Desktop
-
How can I modify the date format in EXCEL with VBA?this is my code:
void ExcelEngine::setCellDateFormat(UINT row,UINT column) { QAxObject *cell = pWorksheet->querySubObject("Cells(int,int)",row,column);//获取单元格对象 if ( cell ) { // cell->dynamicCall("NumberFormat([$-F800]dddd, mmmm dd, yyyy)"); // cell->dynamicCall("SetNumberFormat(mm/dd/yyyy)");//失败 // cell->dynamicCall("NumberFormat(yyyy""年""m""月""d""日"";@)"); // cell->setProperty("NumberFormat","[$-F800]dddd, mmmm dd, yyyy") ; QAxObject *format = cell->querySubObject("NumberFormat "); format->setProperty("NumberFormat","mm/dd/yyyy") ; } delete cell; }
I don't know where it is wrong.
-
How can I modify the date format in EXCEL with VBA?this is my code:
void ExcelEngine::setCellDateFormat(UINT row,UINT column) { QAxObject *cell = pWorksheet->querySubObject("Cells(int,int)",row,column);//获取单元格对象 if ( cell ) { // cell->dynamicCall("NumberFormat([$-F800]dddd, mmmm dd, yyyy)"); // cell->dynamicCall("SetNumberFormat(mm/dd/yyyy)");//失败 // cell->dynamicCall("NumberFormat(yyyy""年""m""月""d""日"";@)"); // cell->setProperty("NumberFormat","[$-F800]dddd, mmmm dd, yyyy") ; QAxObject *format = cell->querySubObject("NumberFormat "); format->setProperty("NumberFormat","mm/dd/yyyy") ; } delete cell; }
I don't know where it is wrong.
-
@studyQt Did you debug it? Is cell != nullptr? Is format != nullptr?
I'm not suredelete cell;
is correct as you're deleting a cell, but you just want to change it's format, right?
@jsulm
oh,thank you for your help,format is NULLptr. Below is the code available:void ExcelEngine::setCellDateFormat(UINT row,UINT column) { QAxObject *cell = pWorksheet->querySubObject("Cells(int,int)",row,column);//获取单元格对象 if ( cell ) { cell->setProperty("NumberFormat","[$-F800]dddd, mmmm dd, yyyy") ; } }
-
@jsulm
oh,thank you for your help,format is NULLptr. Below is the code available:void ExcelEngine::setCellDateFormat(UINT row,UINT column) { QAxObject *cell = pWorksheet->querySubObject("Cells(int,int)",row,column);//获取单元格对象 if ( cell ) { cell->setProperty("NumberFormat","[$-F800]dddd, mmmm dd, yyyy") ; } }