Thread Subject: Writing numbers as text to Excel from Matlab

Subject: Writing numbers as text to Excel from Matlab

From: Conrad

Date: 8 Oct, 2009 17:23:03

Message: 1 of 3

Hi,

I have a cell array containing text and numbers. Among the numbers, some have decimals and others don't. To keep things simple, I have all the numbers as text and I am trying to send this cell array to an Excel file. XLSWRITE converts all the '1.0' data to '1'. Having looked around, I thought PutCellValue (by Michael Robbins) would do it:

  sheet1=Excel.Worksheets.get('Item', 'Sheet1');
  range=get(sheet1,'Range', 'A1');
  PutCellValue(range,'1.0',1);

but I still get the value of 1 on the Excel Sheet. Any ideas?
Thanks

Subject: Writing numbers as text to Excel from Matlab

From: Rune Allnor

Date: 8 Oct, 2009 18:04:10

Message: 2 of 3

On 8 Okt, 19:23, "Conrad " <conr...@gmx.net> wrote:
> Hi,
>
> I have a cell array containing text and numbers. Among the numbers, some have decimals and others don't. To keep things simple, I have all the numbers as text and I am trying to send this cell array to an Excel file. XLSWRITE converts all the '1.0' data to '1'. Having looked around, I thought PutCellValue (by Michael Robbins) would do it:
>
>   sheet1=Excel.Worksheets.get('Item', 'Sheet1');
>   range=get(sheet1,'Range', 'A1');
>   PutCellValue(range,'1.0',1);
>
> but I still get the value of 1 on the Excel Sheet. Any ideas?
> Thanks

This is just as much a problem with display otions in Excel
as with the numerical values. Record a macro in excel where
you select the display format you want. Then open the macro
in the editor, and look at the commands that were used to
set the display options. Last, insert the same commands
at the matlab side when you write the excel file.

It should be something like

range.set('numberformat','0.00');

Rune

Subject: Writing numbers as text to Excel from Matlab

From: Conrad

Date: 8 Oct, 2009 20:40:23

Message: 3 of 3

Thanks for your help Rune. In the meantime i found a way to do it! Using a for loop, I converted the numbers as follows
  excel_table(a,b)=strcat('''',old_table(a,b));
I then used xlswrite with excel_table and that worked.


Rune Allnor <allnor@tele.ntnu.no> wrote in message <c7fedc7c-e966-487d-8d5f-8c2880a3e879@h30g2000vbr.googlegroups.com>...
> On 8 Okt, 19:23, "Conrad " <conr...@gmx.net> wrote:
> > Hi,
> >
> > I have a cell array containing text and numbers. Among the numbers, some have decimals and others don't. To keep things simple, I have all the numbers as text and I am trying to send this cell array to an Excel file. XLSWRITE converts all the '1.0' data to '1'. Having looked around, I thought PutCellValue (by Michael Robbins) would do it:
> >
> > ? sheet1=Excel.Worksheets.get('Item', 'Sheet1');
> > ? range=get(sheet1,'Range', 'A1');
> > ? PutCellValue(range,'1.0',1);
> >
> > but I still get the value of 1 on the Excel Sheet. Any ideas?
> > Thanks
>
> This is just as much a problem with display otions in Excel
> as with the numerical values. Record a macro in excel where
> you select the display format you want. Then open the macro
> in the editor, and look at the commands that were used to
> set the display options. Last, insert the same commands
> at the matlab side when you write the excel file.
>
> It should be something like
>
> range.set('numberformat','0.00');
>
> Rune

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