Thread Subject: Formatting a cell in Excel file using xlswrite

Subject: Formatting a cell in Excel file using xlswrite

From: Stephen

Date: 25 Nov, 2009 14:37:20

Message: 1 of 5

Hi, I'm using xlswrite to transport a matrix from MATLAB to Excel. I want my output in the Excel file to be in the format of dollars and cents (hence, only to two decimal places). However, MATLAB is sending it to Excel in four decimal places. I've tried using "format bank" and "fprintf". But, of course, fprintf won't work for the Excel file because it is not defined for cell inputs. Need some help please!

Subject: Formatting a cell in Excel file using xlswrite

From: Claudio Pedrazzi

Date: 25 Nov, 2009 15:52:21

Message: 2 of 5

have a look at this: I used it for a similar problem, and with a little patience, it works perfectly:

http://www.mathworks.com/support/solutions/en/data/1-33B9ZN/index.html?solution=1-33B9ZN

Subject: Formatting a cell in Excel file using xlswrite

From: DitzaN

Date: 25 Nov, 2009 15:58:42

Message: 3 of 5

Hi,
It is not really dealing the problem but it will solve the problem.
You can change the number you are writing to excel to be with two decimal places.
M=[1.8394 1.2453]
use
M1=round(M*100)/100;
Now write M1 instated of M

Subject: Formatting a cell in Excel file using xlswrite

From: ImageAnalyst

Date: 25 Nov, 2009 16:00:03

Message: 4 of 5

Stephen:
You can't do it using xlswrite() - it simply doesn't give you control
over all those kinds of fine details. You need to either
1) start Excel as an activeX process and set those cell properties via
active x methods and properties, (like in the link Claudio gave you)
or
2) open an existing spreadsheet where the formatting has already been
done in advance (i.e. you created a workbook in Excel and formatted
cells in Excel and saved it out, and then wrote to the same
spreadsheet via xlswrite()).

Subject: Formatting a cell in Excel file using xlswrite

From: TideMan

Date: 25 Nov, 2009 19:13:59

Message: 5 of 5

On Nov 26, 5:00 am, ImageAnalyst <imageanal...@mailinator.com> wrote:
> Stephen:
> You can't do it using xlswrite() - it simply doesn't give you control
> over all those kinds of fine details.  You need to either
> 1) start Excel as an activeX process and set those cell properties via
> active x methods and properties, (like in the link Claudio gave you)
> or
> 2) open an existing spreadsheet where the formatting has already been
> done in advance (i.e. you created a workbook in Excel and formatted
> cells in Excel and saved it out, and then wrote to the same
> spreadsheet via xlswrite()).

or
3) use fprintf to write to a .csv file in the desired format and
import the .csv file into Excel.

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
xlswrite Stephen 25 Nov, 2009 09:39:46
rssFeed for this Thread

Contact us at files@mathworks.com