Question

I am writing a diagramming app in C# .NET 4 and needs the graphic output to be editable in Microsoft Excel. The only 2 vector formats I know for MS Office - CGM and WMF. I am using OpenTK for its OpenGL wrapper, so I have all the vertices.

I also looked at Metafile in .NET 4 but it seems like mainly for reading WMF files. It still outputs into PNG.

I have almost given up hope on CMG already, really not much information to be found. For Windows Metafile Format, I found this link so the question is: has anyone got an opensource library (preferably C#) I can use already, please?

Since I am so bad at this, I need something easy to use like:

wmf = new Wmf();
wmf.addLine(x, y);
wmf.addRectangle(x, y, w, h);
wmf.addEllipse(x, y, radiusx, radiusy);
wmf.save("welldone.wmf");

The rest of the posts around SO and Google doesn't seem to care if it's vector or raster format so I hope to get some additional help. Thanks.

Was it helpful?

Solution

Check out the WMF Library: http://wmf.codeplex.com/

var wmf = new WmfDocument();
wmf.Width = 1000;
wmf.Height = 1000;
wmf.Format.Unit = 288;
wmf.AddPolyFillMode(PolyFillMode.WINDING);
wmf.AddCreateBrushIndirect(Color.Blue, BrushStyle.BS_SOLID);
wmf.AddSelectObject(0);
wmf.AddCreatePenIndirect(Color.Black, PenStyle.PS_SOLID, 1);
wmf.AddSelectObject(1);

wmf.AddLine(Point start, Point end);
wmf.AddRectangle(x, y, width, height);
wmf.AddEllipse(x, y, width, height);

wmf.AddDeleteObject(0);
wmf.AddDeleteObject(1);
wmf.Save(path);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top