File Exchange

image thumbnail

xlsgraph

version 1.0 (9.41 KB) by

Creates graphs from existing Excel sheet containing column data.

7 Downloads

Updated

View License

xlsgraph(xtitle,ytitle,chartype,chart_title,filename,sheetname)

xlsgraph : creates an Excel graph by searching specified sheet for selected columns headers.

xtitle: title(s) of column to be x-axis (picked from titles).

ytitle: title(s) of column to be y-axis (picked from titles).

chartype: integer number corresponds to chart type (from the list below) or string of characters to name the chart type (ex. '3DLine')

chart_title: This title will be used for both chart sheet name and chart title.

filename: Name of excel file.

sheetname: sheet name.

CHARTYPE:
1- ColumnClustered
2- ColumnStacked
3- ColumnStacked100
4- 3DColumnClustered
5- 3DColumnStacked
6- 3DColumnStacked100
7-3DColumn
8-BarClustered
9-BarStacked
10-BarStacked100
11-3DBarClustered
12-3DBarStacked
13-3DBarStacked100
14-Line
15-LineStacked
16-LineStacked100
17-LineMarkers
18-LineMarkersStacked
19-LineMarkersStacked100
20-3DLine
21-Pie
22-3DPie
23-PieOfPie
24-PieExploded
25-3DPieExploded
26-BarOfPie
27-XYScatter
28-XYScatterSmooth
29-XYScatterSmoothNoMarkers
30-XYScatterLines
31-XYScatterLinesNoMarkers
32-Area
33-AreaStacked
34-AreaStacked100
35-3DArea
36-3DAreaStacked
37-3DAreaStacked100
38-Doughnut
39-DoughnutExploded
40-Radar
41-RadarMarkers
42-RadarFilled
43-Surface
44-SurfaceWireframe
45-SurfaceTopView
46-SurfaceTopViewWireframe
47-Bubble
48-Bubble3DEffect
49-StockHLC
50-StockOHLC
51-StockVHLC
52-StockVOHLC


Examples:

xlsgraph('col_1','col_2','XYScatterSmooth','1 vs 2','data.xls','Data');
xlsgraph('col_1','col_4','XYScatterSmooth','1 vs 4','data.xls','Data');
xlsgraph({'col_1','col_2'},{'col_3','col_4'},'Line','1&2 vs 3&4','data.xls','Data');

See also XLSREAD, XLSFINFO, XLSWRITE, XLSCELL, XLSHEETS, MSOPEN, XLSCHART

Comments and Ratings (12)

Nadezhda

hi!! Could you give an example of Excel in Spanish version, Please

prashant

I am getting following error
No appropriate method, property, or field Font for class Interface.Microsoft_Excel_12.0_Object_Library.ChartTitle.

Error in ==> xlsgraph at 342
Excel.ActiveChart.ChartTitle.Font.Bold = 1;

is it because of Office 20007

-------------------------- Excel2007 -----------------------------

Hi,
see below how I got it working with Office2007 (and Office2003).

I changed these lines:
Do not use

Excel.ActiveChart.SeriesCollection(1).Delete;

but

try %Office2007 HK
for zz = 1:nr
Excel.ActiveChart.SeriesCollection(1).Delete;
end
end

Has to be done twice in the code.

I commented these lines:
% Excel.ActiveChart.PlotArea.Select; %HK
% Excel.Selection.Border.ColorIndex = 16;%HK
% Excel.Selection.Border.Weight = 1;%HK
% Excel.Selection.Border.LineStyle = 1;%HK
% Excel.Selection.Interior.ColorIndex = 0;%HK
% Excel.Selection.Border.ColorIndex = 2;%HK
% Excel.Selection.Border.Weight = 1;%HK

% Excel.ActiveChart.Axes(1).Crosses = 1; %HK

% Excel.Selection.Border.ColorIndex = 1; HK
% Excel.Selection.Border.Weight = 1; HK

% Excel.ActiveChart.Legend.LegendEntries(i).LegendKey.Border.ColorIndex = colors(k); HK
% Excel.ActiveChart.Legend.LegendEntries(i).LegendKey.Border.Weight = 3; HK
% Excel.ActiveChart.Legend.LegendEntries(i).LegendKey.Border.LineStyle= 1; HK

Bye, Hinrich.

Abdul Waheed

Peng Xi

Can you please help me out in drawing the graph on same excel file.

Needless to say that the work is awesome, but I can't spare enough of time on this, as my research will hamper otherwise.

Respecto al problema de Javier Seminario y la solución de Hinrich Koetter

Si teneis Excel en castellaño o español, teneís que sustituir 'R' y 'C' por 'L' (Linea) y 'C' (Columna)

Thank you very much! Very useful tool! For everybody who has problems like mentioned by javier seminario: You have to change some lines if you have another system setup (language):

Excel.ActiveChart.SeriesCollection(i).XValues = ['=' sheetname ' R2C1:R' int2str(nr+1) 'C1'];
Excel.ActiveChart.SeriesCollection(i).Values = ['=' sheetname '!R2C' int2str(i+1) ':R' int2str(nr+1) 'C' int2str(i+1)];

In this both lines as well as in the following both you have to change R (Row) and C (Column) to the abbreviations used in your language (german: Z (Zeile), S (Spalte)).

Excel.ActiveChart.SeriesCollection(noOfSeries).XValues = ['=' sheetname '!R2C' int2str(locx(j)) ':R' int2str(nr+1) 'C' int2str(locx(j))];
Excel.ActiveChart.SeriesCollection(noOfSeries).Values = ['=' sheetname '!R2C' int2str(locy(j)) ':R' int2str(nr+1) 'C' int2str(locy(j))];

In the following line you have to change word 'Sheet' (only the last one in quotation marks) to the adequate word in your language (german: Tabelle).

Sheet = get(Workbook.Sheets,'Item',['Sheet',num2str(i)]);

You can use try and catch to capture different languages.

A U

This function was a great start and I was using it often with some additions/modifications. Then they upgraded me to Office 2007 at work and it was down hill from there. Seems that many of the properties have changed or are no longer available to set and numerous errors occur now. I managed to strip alot of the extras out so it would run but the graphs are all messed up when I open excel (extra series plotted for no apparent reason).

javier seminario

could you help me with this error?
??? No public field DisplayUnit exists for class Interface.excel.application.ActiveChart.Axes.

Error in ==> C:\Documents and Settings\juan albizua\Escritorio\xls\xlsgraph\xlsgraph.m
On line 368 ==> Excel.ActiveChart.Axes(1).DisplayUnit = 'xlHundreds';

javier seminario

i have this error whith this program
1)??? Invoke Error, Dispatch Exception:
Source: Microsoft Excel
Description: Imposible asignar la propiedad XValues de la clase Series.
Help File: XLMAIN8.HLP
Help Context ID: 0.

Error in ==> C:\Documents and Settings\juan albizua\Escritorio\xls\xlsgraph\xlsgraph.m
On line 267 ==> NewSeries.XValues = ['=' sheetname '!R' int2str(R+1) 'C' int2str(C) ':R' int2str(end_R-1) 'C' int2str(C)];
could you help me? tankx

Peng Xi

It is very enlightening -- can't believe you have done so wonderful work. I have used it in my application.
Of course, you are somewhat careless as the guy writing xlschart--you have common bugs. However I think it is good to leave some bug to the user, otherwise they (we) cannot learn anything from your work.
I have managed to plot the chart in the activesheet(not to open a new chart). It is useful when you need to see the data and the figure at the same time. If someone who is interested, feel free to contact me. :)
Thank you!

Yasir Ahmed

Updates

Search Criteria Changed to "Match Case"

MATLAB Release
MATLAB 6.5 (R13)
Acknowledgements

Inspired by: xlschart

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today