3

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.

Jake
  • 11,273
  • 21
  • 90
  • 147

1 Answers1

10

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);
Papn Kukn
  • 156
  • 1
  • 3
  • 1
    wow thanks. timely help. but did you create this account just to help us with WMF issues? Will check that out and then come back to mark as answer if it works. Thanks again. – Jake Mar 05 '12 at 01:37
  • 2
    Thanks for your work. Really easy to extend. I have added additional records for Line, Move, Arc and Ellipse. Are you interested to add it to the source? – Jake Mar 05 '12 at 07:18
  • 1
    Actually I was searching for the solution myself and then decided to build a new library. Your question helped me decide how the code flow should look like. Thanks for the additional records, have been accepted at CodePlex. – Papn Kukn Mar 05 '12 at 12:15