Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One possible solution is to use the system time formatter (like: _tcsftime, strftime, wcsftime) to format the date/time structure to the locale of the running system. Since both your program and excel is expected to run on the same PC, it should work properly without even knowing how the local date/time string look like.</p> <p>As a fall-back solution, you may have to provide a series of hard-coded format string and/or a user-manually-entered string in the option-configuration section of your program, just in case the default locale format fails.</p> <p>Additional informations after first reply comment from OP: --------------</p> <p>locale setting affect the text-display presentation of a datetime-binary-object in the UI only. Such datetime-binary-object is alway stored as a binary structure in a very consistent way, irregardless of locale setting even in its each different contexts, be it in Excel (Date/Time format cell), C++ (various structure depends on api), VisualBasic (Variant). </p> <p>So if your intention is to export the datetime binary structure to excel, not as a strng, you can alway use the "variant" type to store the date value as excel-automation uses the IDispatch interface. You can forget about the locale setting totally.</p> <p>Adding of code fragment to export datetime variant and format the cell by code: ----------------</p> <p>I am using MFC so the the code is very simple, you may have to convert to winapi youself</p> <pre><code>_Application app; if (!app.CreateDispatch("Excel.Application")) { AfxMessageBox("Cannot start Excel !"); return; } app.SetVisible(TRUE); COleVariant VOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR); Workbooks objbooks = app.GetWorkbooks(); _Workbook objbook = objbooks.Add(VOptional); Worksheets objsheets = objbook.GetWorksheets(); _Worksheet objsheet = objsheets.GetItem(COleVariant((short)1)); // get current date time COleDateTime timeCurrent = COleDateTime::GetCurrentTime(); // setting date values Range range; range = objsheet.GetRange(COleVariant("A2"), COleVariant("B3")); range.SetValue(COleVariant(timeCurrent)); // range.SetNumberFormat(COleVariant("dd/mm/yyyy")); range.SetNumberFormat(COleVariant("dddd, mmmm dd, yyyy")); AfxMessageBox("Done..."); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload