예제 #1
0
        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
예제 #2
0
        /// <summary>
        /// Reads a previously stored ods file containing the student grade information and updates the current list with
        /// the students grade information.
        /// </summary>
        /// <param name="filename">file name and path as a string</param>
        public static void getStudentData(string filename)
        {
            DataSet studentData;

            try
            {
                studentData = fileAccess.ReadOdsFile(filename);  // Open file or fail
            }
            catch { return; }

            // Check the file opened has the right data columns
            if (studentData.Tables[0].Rows[0][0].ToString() != "id" &&
                studentData.Tables[0].Rows[0][1].ToString() != "firstname" &&
                studentData.Tables[0].Rows[0][2].ToString() != "lastname" &&
                studentData.Tables[0].Rows[0][3].ToString() != "username" &&
                studentData.Tables[0].Rows[0][4].ToString() != "active" &&
                studentData.Tables[0].Rows[0][5].ToString() != "grade")
            {
                return;
            }

            int col = 0;  // temp column counter

            // Set the column names
            foreach (DataColumn logColumn in studentData.Tables[0].Columns)
            {
                logColumn.ColumnName = studentData.Tables[0].Rows[0][col++].ToString();
            }

            studentData.Tables[0].Rows[0].Delete();

            uint stuId    = 0;
            int  stuIndex = -1;

            // Loop through all students in the sheet matching id in datafile with students in the loaded list
            foreach (DataRow stu in studentData.Tables[0].Rows)
            {
                stuId = uint.Parse(stu["id"].ToString());                 // Get student ID from the file data

                stuIndex = studentList.FindIndex(sId => sId.id == stuId); // Find the list index for that student -1 if not found
                if (stuIndex >= 0)
                {
                    studentList[stuIndex].grade = stu["grade"].ToString();  // Copy the grade from the data file to the student in the list
                }
            }
        }