[Mono-list] C# Office Ubuntu/Windows

Wolfgang Mauer wolfgang.mauer at kabelmail.de
Thu Nov 3 09:02:57 UTC 2016


Hi all,

i found an “easy way” to manipulate/create ODF. In my case AODL throws exception because it don’t understand .ott:(

This unzip a ott, assign data to user-defined fields and zip to an odt


        private void InitDocument(string template, string fileName, IList<IModel> headers, ListStore table, IList<IModel> footers)

        {

            const string contentFile = "content.xml";

            var path = Path.GetTempPath() + fileName;

            if (File.Exists(path))

                File.Delete(path);

            var tmpPath = Path.GetDirectoryName(path) + Path.DirectorySeparatorChar + Guid.NewGuid();

            var dirInfo = Directory.CreateDirectory(tmpPath);

            ZipFile.ExtractToDirectory(template, dirInfo.FullName);

            var xmlDoc = XDocument.Load(dirInfo.FullName + Path.DirectorySeparatorChar + contentFile);

            var elements = xmlDoc.Descendants(XName.Get("user-field-decl", "urn:oasis:names:tc:opendocument:xmlns:text:1.0"));

            foreach (var element in elements)

            {

               var attribute = element.Attributes().First(a => a.Name == "text:name");

                if (attribute != null)

                    ApplyData(attribute.Value, headers, table, footers);

            }

            xmlDoc.Save(dirInfo.FullName + Path.DirectorySeparatorChar + contentFile);

            ZipFile.CreateFromDirectory(dirInfo.FullName, path);

            dirInfo.Delete(true);

            if (Directory.Exists(dirInfo.FullName))

                Directory.Delete(dirInfo.FullName);

        }

 

 

Von: Mono-list [mailto:mono-list-bounces at lists.xamarin.com] Im Auftrag von Wolfgang Mauer
Gesendet: Mittwoch, 2. November 2016 14:16
An: 'Marco Ridoni' <m.ridoni at gmail.com>; Mono-list at lists.ximian.com
Betreff: Re: [Mono-list] C# Office Ubuntu/Windows

 

Ok, but if the user choose „saveas“ ? :)

 

Von: Mono-list [mailto:mono-list-bounces at lists.xamarin.com] Im Auftrag von Marco Ridoni
Gesendet: Mittwoch, 2. November 2016 13:41
An:  <mailto:Mono-list at lists.ximian.com> Mono-list at lists.ximian.com
Betreff: Re: [Mono-list] C# Office Ubuntu/Windows

 

 

2016-11-02 13:37 GMT+01:00 Wolfgang Mauer <wolfgang.mauer at kabelmail.de <mailto:wolfgang.mauer at kabelmail.de> >:

close-listener.


AODL is just a library to generate documents, you can generate it into a temporary directory, read it back into a database and delete the previously-generated copy.

 

m.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dot.net/pipermail/mono-list/attachments/20161103/dd853474/attachment.html>


More information about the Mono-list mailing list