简体   繁体   中英

Extract Visio diagram from word document using open xml?

I am trying to parse the word document, It has visio diagram and images. I am not able to extract diagram and save it in visio format (.vsd, .vdx, .vsdx, .vsdm) Using C# Open XML.

I have found and answer to my own question. below is the code if any one its..

Below code will help you get all the image in word document.

foreach (ImagePart imagePart in doc.MainDocumentPart.ImageParts)
{
    var uri = imagePart.Uri;
    var IdR = doc.MainDocumentPart.GetIdOfPart(imagePart);
    string FileExtension = uri.OriginalString.Split('.').Last();
    var filename = uri.ToString().Split('/').Last();
    stream = doc.Package.GetPart(uri).GetStream();
    Bitmap b = new Bitmap(stream);
    string FilePath = @"C:\test"." + FileExtension;
    b.Save(FilePath);
}

Below will help you get the embedded object in word document like: Visio, MP3 video.

var IdR = doc.MainDocumentPart.GetIdOfPart(embeddedobjectpart);
string FileExtension = embeddedobjectpart.Uri.OriginalString.Split('.').Last();
FileExtension = "vsd";
stream = doc.Package.GetPart(embeddedobjectpart.Uri).GetStream();
long length = stream.Length;
byte[] byteStream = new byte[length];
stream.Read(byteStream, 0, (int)length);
string FilePath =@"C:\test"." + "." + FileExtension;
fstream = new FileStream(FilePath, FileMode.OpenOrCreate)
fstream.Write(byteStream, 0, (int)length);
fstream.Close();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM