View Single Post
  #54   Report Post  
Posted to microsoft.public.excel.programming
dpb dpb is offline
external usenet poster
 
Posts: 109
Default Check how date is entered

On 5/8/2018 4:04 PM, GS wrote:
....

... In cases where raw data is imported to a
spreadsheet I'll pre-design a template to receive that data in its
_expected_ format so it displays in the user's _desired_ format. After
all, output data from most apps is usually just plain text. (CSV/TSV or
the like)

....

Well, I tried the following:

1) created a sheet like the previous example with the two formats
m/d/yyyy, d/m/yyyy in A1, B1, respectively containing dummy data.

2) saved the file

3) wrote to those two cells via the ML COM routine the content of the
same as previous text file...

dates=importdata('dates.txt'); % read the file to a cell string
dates=strip(split(dates)); % split at the ',' and clean
xlswrite('dates.xls',dates,1,'A1:B1') % and put into the formatted cells

Unfortunately, that doesn't seem to override the MS penchant for
interpreting by system locale; the format is OK, but the serial date is
still based on m/d/yyyy.

I don't know much about Excel, but that's about the only way
programmatically to push data into it I know; I was able to manually
import the file as text with the import tool but it allows you to set
the date format on a column-by-column basis; I suppose maybe there's
some way to emulate this programmatically?

All in all, Excel continues to make me exceedingly glad I don't have to
try to use it for engineering work... :)

And, yes, I understand this is trying to fix a sorry way to run a
railroad...but it seems to be the OPs RR. :)

--