Posts Tagged ‘Office’

Excel poisoning #10: fit print area in one page

December 18, 2011

In previous posts we added a new chart to current worksheet, what if we want to print the whole area only in one page ?

myWorksheet.PageSetup.PrintArea = rangeDataAndChart.Address;
myWorksheet.PageSetup.Orientation = XlPageOrientation.xlLandscape;
myWorksheet.PageSetup.Zoom = false;

Thank you to EnricoG for zoom tip. 😉

Technorati tags: Excel, Csharp

Excel poisoning #9: customizing chart programmatically (C#)

December 17, 2011

Customize graph color.

Here is a brief sample, part III:

IOPXLS.Series chartSeries1st = myCharts.SeriesCollection(1) as IOPXLS.Series;
chartSeries1st.Format.Fill.ForeColor.RGB = (int)XlRgbColor.rgbOrange;

This snippet change color for 1st series of data.

Technorati tags: Excel, Csharp

Excel poisoning #8: customizing chart programmatically (C#)

December 11, 2011

Want to change font size to axis’ labels?

Here is a brief sample, part II:

IOPXLS.Axis chartAxisY = myChart.Axes(XlAxisType.xlCategory) as IOPXLS.Axis;
chartAxisY.TickLabels.Font.Size = myChart.ChartTitle.Characters.Font.Size; 

This snippet sets axis label foint size, same as chart title.

Technorati tags: Excel, Csharp

Excel poisoning #7: adding chart programmatically (C#)

December 9, 2011

Sometimes you collect data in very different ways, but format is every time is similar … ie a 3-columns table, a pivot table, ecc.
Same way, you need to add same pre-formatted customized chart, but adding from scratch is boring and time-expensive.

Well, you can add programmatically, via macro … or via C# 😉

Here is a brief sample, part I:

IOPXLS.ChartObjects xlsCharts = (IOPXLS.ChartObjects)myWorkSheet.ChartObjects(Type.Missing);
IOPXLS.ChartObject myCharts = (ChartObject)xlsCharts.Add(500, 100, 500, 500);
IOPXLS.Chart myChart = myCharts.Chart;

myChart.ChartType = XlChartType.xl3DPie;
myChart.SetSourceData(myRangeData, System.Reflection.Missing.Value);

(where IOPXLS is Microsoft.Office.Interop.Excel namespace)
This snippet contains few basic steps: add a chart, set position and dimentions, type (3D pie) and data source.

All chart type are available here: XlChartType Enumeration.

Technorati tags: Excel, Csharp

VSTO office ribbon [bookmark]

July 27, 2011

Working with VSTO office ribbon, might be sometimes hard.
The more info you have, the simpler it will be.

Here is a free chapter from book Excel 2007 VBA Programmer’s Reference

Read free chaper 14 here: Ribbon X, ch 14.