/// <summary> /// Stores the student data in an excel readable ods file /// </summary> /// <param name="filename">path and filename to store the data under</param> public static void storeStudentData(string filename) { DataTable studentInfo = new DataTable("StudentInfo"); DataSet studentData = new DataSet(); // Set up columns Student s = new Student(); // Build the columns for the data studentInfo.Columns.Add("id", typeof(string)); studentInfo.Columns.Add("firstname", typeof(string)); studentInfo.Columns.Add("lastname", typeof(string)); studentInfo.Columns.Add("username", typeof(string)); studentInfo.Columns.Add("active", typeof(string)); studentInfo.Columns.Add("grade", typeof(string)); // Add a header row for readability studentInfo.Rows.Add("id", "firstname", "lastname", "username", "active", "grade"); // Loop through the student list storing the data in the data table foreach (Student stu in studentList) { studentInfo.Rows.Add(stu.id.ToString(), stu.firstname, stu.lastname, stu.username, stu.active.ToString(), stu.grade); } // Add the table to the dataset studentData.Tables.Add(studentInfo); // Write the dataset as an ODS file fileAccess.WriteOdsFile(studentData, filename); }
public static void Test() { string inFile = @"D:\username\Desktop\Mappe1.ods"; string outFileXml = @"D:\username\Desktop\mysheet.xml"; string outFile = @"D:\username\Desktop\notmysheet.ods"; if (System.Environment.OSVersion.Platform == System.PlatformID.Unix) { inFile = "/root/Documents/mysheet.ods"; outFileXml = "/root/Documents/mysheet.xml"; outFile = "/root/Documents/notmysheet.ods"; } // End if (System.Environment.OSVersion.Platform == System.PlatformID.Unix) OdsReaderWriter odr = new OdsReaderWriter(); using (System.Data.DataSet ds = odr.ReadOdsFile(inFile)) { System.Console.WriteLine(ds.Tables.Count); using (System.IO.FileStream fs = System.IO.File.OpenWrite(outFileXml)) { //ds.WriteXml(fs, System.Data.XmlWriteMode.WriteSchema); ds.WriteXml(fs, System.Data.XmlWriteMode.IgnoreSchema); } // End Using fs odr.WriteOdsFile(ds, outFile); } // End Using ds } // End Sub Test