Inserting pictures using interop (C#) into powerpoint - c#

can someone help me out?
I'm trying to insert pictures into powerpoint using this code:
PPT.Shape sheetShape = slides[slideIndex].Shapes[shapeName];
...
slides[slideIndex].Shapes.AddPicture(fileName, MsoTriState.msoFalse, MsoTriState.msoTrue, sheetShape.Left, sheetShape.Top, sheetShape.Height, sheetShape.Width);
my problem is, that it shifts the inserted picture like:
http://i.imgur.com/Ia2MVbk.png
So both have the same position but not really.
What am I doing wrong?
Thank you.

So because there is still no answer, I have to answer myself.
The problem with the charts I wanted to insert was, that they got rotated before (export from excel as image, then rotate) but powerpoint act like they are not rotated, so they have the wrong size and positiion.
But then I thought, there must be a possibility to rotate them in powerpoint, not before.
And thats it.
So I solved my problem with not exporting the charts from excel, but c&p them directly from excel and then rotate them in powerpoint.
Thats how it looks for me now:
chart.CopyPicture();
PPT.ShapeRange sr = slides[slideIndex].Shapes.PasteSpecial();
sr.Rotation = 90;
sr.Left = sheetShape.Left+30;
sr.Top = sheetShape.Top;
sr.Width = sheetShape.Width;
sr.Height = sheetShape.Height;
sheetShape.Delete();
Hope it helps if someone else got the problem.

Related

Excel C# API Chart class Interior property missing

I am trying to create a chart with Excel API in C#. It is going really well, but I don't have some fields.
For example:
Format Excel Chart Background using C#
At this question, James' answer is something I'm looking for but:
The object does not have an Interior property.
And again:
Chart Properties
I see something like ChartColor:
But my charts don't have it.
I though it depends on the type of the chart, but it is just defined inside and doesn't affect the fields (tried to do something like casting, but it was just 'not-smart' heroic try).
I also tried to do an example of chart and just ascribe all attributes, but still there is nothing like Color.
I don't want a background image, just a background hue!
I have the latest Microsoft.Office.Interop.Excel library, but tried on older ones and effect is the same.
Where is the problem?
P.S.
I'm also working with copying all attributes of chart except data, name and axis names. If someone of You did something like that, I would be grateful for any information.
EDIT:
Fixed it just by load example chart and use SetSourceData. But why I can't do it programmatically?
"Where is ChartColor?": It's probably just an Intellisense bug. Usually happens when I sleep the computer too many times without closing VS. Try closing and reopening VS. Also, have you tried just running the code with chart.ChartColor?
"There's nothing like interior": Interior refers to an sub-area that can be formatted. The chart object itself isn't what you want to color. It's the ChartArea that contains Interior, which has a ColorIndex, so try
Excel.Interior interior = chart.ChartArea.Interior;
I'm sorry that wasn't clear in Format Excel Chart Background using C#. You'll need to be wary of posters that answer their own questions. Sometimes, it's ok, but more often, it's "I fixed it with this line" which doesn't help anyone else when taken out of context.
"Where's my problem?": It depends on your implementation. Including some example code helps tremendously on StackOverflow. Some are looking to create a chart as part of a worksheet, like:
Excel.Shape shape = worksheet.Shapes.AddChart2();
Excel.Chart chart = shape.Chart;
Or some developers want to create a chart as a new sheet, like this:
Excel.Chart chart = workbook.Charts.Add();
These are both charts, but behave differently because of their implementation.

Remove Gridlines in LineChart in Excel using C#.net (Microsoft.Office.Interop.Excel)

I have a problem in removing/hiding the grid lines in LINE CHART in excel using C#.Net MVC with the DLL (Microsoft.Office.Interop.Excel) I want to remove it or just hide since it was the client's need. I've seen a lot of article but it's still not working for me.
Please click here for my sample excel
The 3 Numbers in the image is the thing that I want to remove or hide.
And here is my code for Border, ChartArea and PlotArea transparency.
//Plot Area
chartPage.PlotArea.Format.Fill.Solid();
chartPage.PlotArea.Format.Fill.ForeColor.RGB = (int)XlRgbColor.rgbWhite;
chartPage.PlotArea.Format.Fill.Transparency = (float)1;
//Chart Area
chartPage.ChartArea.Format.Fill.Solid();
chartPage.ChartArea.Format.Fill.ForeColor.RGB = (int)XlRgbColor.rgbWhite;
chartPage.ChartArea.Format.Fill.Transparency = (float)1;
//Border
chartPage.ChartArea.Format.Line.ForeColor.RGB = (int)XlRgbColor.rgbWhite;
chartPage.ChartArea.Format.Line.Transparency = (float)1;
My Problem is the Gridlines, please refer in the image.
Any helps would be appreciated.
Thanks!
I've already found a solution for this problem.
I hope this will help to all of the guys who has the same problem.
//This will get the X-Axis (#3 in the image)
Axis xAxis = (Axis)chartPage.Axes(XlAxisType.xlValue, XlAxisGroup.xlPrimary);
//This will get the Y-Axis (#2 in the image)
Axis yAxis = (Axis)chartPage.Axes(XlAxisType.xlCategory, XlAxisGroup.xlPrimary);
//This will delete the Grid Lines (#1 in the image)
xAxis.MajorGridlines.Delete();
//This will delete the X-Axis (#3 in the image)
xAxis.Delete();
//This will delete the Y-Axis (#2 in the image)
yAxis.Delete();
Cheers!

Stop repeating image when usung graphics.DrawImage

I am trying to merge two images and show them on pictureBox but when I show any image small then the size of pictureBox it repeats
I am using this to merge with other image
grfx = Graphics.FromImage(Image1); // Grass.png
grfx.DrawImage(Image2,0,0); // Mario.png
Here is the result
Output of my code
In the picture I want Mario to show only once.
Thanks,
I figured it out myself with some hint from little hint found on internet. Problem was that I changed
pictureBox.BackgroundImageLayout = ImageLayout.Tile
to
pictureBox.BackgroundImageLayout = ImageLayout.none
btw thanks for you intrest.

How to rotate text in Excel spreadsheet cell using OpenXML and C#

I'm trying to finish little application which is creating MS Excel spreadsheet filled with some data taken from a database. I got stucked with few things. One of these is how to rotate a text in a spreadsheet cell. I was trying to do it in that way:
SpreadsheetStyle style = SpreadsheetReader.GetDefaultStyle(spreadSheet);
style.AddAlignment(new Alignment() {
TextRotation = 90
});
but of course it didn't work. I'm using WorksheetWriter class to build excel doc.
I couldn't find anything helpful in Google so I hope to find some help here :)

Problem with coordinate system and displaced Text in different PDFs using iTextSharp

I'm working with iTextSharp and .NET 3.5 SP1 (in C#, as you can guess) and modify some existing PDFs using the PdfStamper class. Now I've got two problems:
Transforming the coordinate system
As I see it, iTextSharp is using (postscript?) points as unit of measurement, but I'd like to transform these coordinates to millimeter. Now, how's the best way to achieve this?
Taking a look in the documentation revealed the following approach:
PdfContentByte cb = new PdfContentByte();
System.Drawing.Drawing2D.Matrix scale = new System.Drawing.Drawing2D.Matrix(
0.352777778, 0, 0.352777778, 0, 0, 0); // 1 point = 0.352777778 mm
cb.Transform(scale);
I hope I got the transformation matrix right. But the problem is: There is no System.Drawing.Drawing2D Assembly! Was this assembly dropped or what happened to it? What can I do to transform the coordinates of iTextSharp to millimeter. Am I on the wrong way here?
Text in PDF gets displaced in a different PDF using the same coordinates
I noticed that while modifying two different PDF files with the same content, that the same coordinates got displaced and the text is not being placed at the exact same positions. What is causing this and how can I prevent it?
This is the first PDF:
This is the second PDF, created using the exact same coordinates in iTextSharp:
Any help is appreciated.
But the problem is: There is no
System.Drawing.Drawing2D Assembly! Was
this assembly dropped or what happened
to it? What can I do to transform the
coordinates of iTextSharp to
millimeter. Am I on the wrong way
here?
http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.matrix.aspx (in System.Drawing.dll)
Okay, I solved the second problem with the text being displaced despite the same coordinates being used.
As it turned out, the first PDF included some non-visible trimming space, the second didn't. The trimming space isn't visible 'cause the view space was cropped using the PDF creator, but as it appears the trimming space was still there and counted for the coordinates.

Categories

Resources