Thread Subject: Write date in excel

Subject: Write date in excel

From: Rosy

Date: 5 Nov, 2008 00:23:08

Message: 1 of 3

Hello

I am writing to ask a question on writing date in excel.

What I am trying to do is to write date converted from date number in
excel.
For example,
A = [730238
730239
730240
730241
730242
730243
730244
730245
730246
730247];

Date = datestr(A);
xlswrite(xlsfilename, Date);

However, the dates were not written in a cell but as follows

2 8 / 0 4 / 9 9
2 9 / 0 4 / 9 9
3 0 / 0 4 / 9 9
0 1 / 0 5 / 9 9
0 2 / 0 5 / 9 9
0 3 / 0 5 / 9 9
0 4 / 0 5 / 9 9
0 5 / 0 5 / 9 9
0 6 / 0 5 / 9 9

It would be great if you could help me.
Thanks,

Eu Gene

Subject: Write date in excel

From: gmtechproject@gmail.com

Date: 5 Nov, 2008 00:51:32

Message: 2 of 3

On Nov 4, 4:23=A0pm, Rosy <egrosa...@gmail.com> wrote:
> Hello
>
> I am writing to ask a question on writing date in excel.
>
> What I am trying to do is to write date converted from date number in
> excel.
> For example,
> A =3D [730238
> 730239
> 730240
> 730241
> 730242
> 730243
> 730244
> 730245
> 730246
> 730247];
>
> Date =3D datestr(A);
> xlswrite(xlsfilename, Date);
>
> However, the dates were not written in a cell but as follows
>
> 2 =A0 =A0 =A0 8 =A0 =A0 =A0 / =A0 =A0 =A0 0 =A0 =A0 =A0 4 =A0 =A0 =A0 / =
=A0 =A0 =A0 9 =A0 =A0 =A0 9
> 2 =A0 =A0 =A0 9 =A0 =A0 =A0 / =A0 =A0 =A0 0 =A0 =A0 =A0 4 =A0 =A0 =A0 / =
=A0 =A0 =A0 9 =A0 =A0 =A0 9
> 3 =A0 =A0 =A0 0 =A0 =A0 =A0 / =A0 =A0 =A0 0 =A0 =A0 =A0 4 =A0 =A0 =A0 / =
=A0 =A0 =A0 9 =A0 =A0 =A0 9
> 0 =A0 =A0 =A0 1 =A0 =A0 =A0 / =A0 =A0 =A0 0 =A0 =A0 =A0 5 =A0 =A0 =A0 / =
=A0 =A0 =A0 9 =A0 =A0 =A0 9
> 0 =A0 =A0 =A0 2 =A0 =A0 =A0 / =A0 =A0 =A0 0 =A0 =A0 =A0 5 =A0 =A0 =A0 / =
=A0 =A0 =A0 9 =A0 =A0 =A0 9
> 0 =A0 =A0 =A0 3 =A0 =A0 =A0 / =A0 =A0 =A0 0 =A0 =A0 =A0 5 =A0 =A0 =A0 / =
=A0 =A0 =A0 9 =A0 =A0 =A0 9
> 0 =A0 =A0 =A0 4 =A0 =A0 =A0 / =A0 =A0 =A0 0 =A0 =A0 =A0 5 =A0 =A0 =A0 / =
=A0 =A0 =A0 9 =A0 =A0 =A0 9
> 0 =A0 =A0 =A0 5 =A0 =A0 =A0 / =A0 =A0 =A0 0 =A0 =A0 =A0 5 =A0 =A0 =A0 / =
=A0 =A0 =A0 9 =A0 =A0 =A0 9
> 0 =A0 =A0 =A0 6 =A0 =A0 =A0 / =A0 =A0 =A0 0 =A0 =A0 =A0 5 =A0 =A0 =A0 / =
=A0 =A0 =A0 9 =A0 =A0 =A0 9
>
> It would be great if you could help me.
> Thanks,
>
> Eu Gene
you can write your data with comma separated values in notepad,and
save with extension .csv it automatically write in column wise.then
you can read the data from excel sheet.

Subject: Write date in excel

From: Walter Roberson

Date: 5 Nov, 2008 00:55:34

Message: 3 of 3

Rosy wrote:

> Date = datestr(A);
> xlswrite(xlsfilename, Date);

If you are communicating with a "real" Excel (via a COM service on MS Windows) then
there might be a way such as (guessing here)

xlswrite(xlsfilename, cellstr(Date));

If, however, you are on any of the other operating systems or you (for whatever reason)
cannot get a COM session established to Excel (e.g., if you don't actually have Excel
installed and are just wanting the file format), then xlswrite is only able to write in
comma separated value format (CSV), not true Excel files. And if you are in that
situation, then you have to deal with the fact that xlswrite will treate each individual
character as being a separate array value (which is how characters are stored in Matlab)
and will write them out one per cell, with the delimeter in between. In order to avoid
that happening, you have to use dlmwrite() instead and tell it that the cell delimiter
is '' (the empty string): that will cause dlmwrite to put each row of text into a cell
(one per line). But if you are doing that, then you have a bit of a mess if you are trying
to combine text and numeric data in the output; the only way to get around that is to
convert -everything- to text ahead of time (e.g., using sprintf() or num2str())
and write it all out using dlmwrite() with the delimiter set to '' (the empty string),
and in this situation you have to "manually" put in the commas where you want them.

For example,

dlmwrite(xlsfilename, ...
  [char(Date), repmat(',', size(Date,1), 1), num2str(SomeRowVector .')], ...
  'Delimiter', '');

just to get the date followed by a comma followed by a number, one per line.

--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com