Exemplo n.º 1
0
        public static XS__spreadsheet[] Load_fromURI(
            XS__RootMetadata root_ref_in,
            params Uri[] filePath_in
            )
        {
            XS__spreadsheet[] _output
                = new XS__spreadsheet[filePath_in.Length];

            for (int i = 0; i < filePath_in.Length; i++)
            {
                if (filePath_in[i].IsFile)
                {
                    _output[i] = XS__spreadsheet.Load_fromFile(
                        filePath_in[i].LocalPath
                        )[0];
                    // no need! everything's been taken care at: XS__spreadsheet.Load_fromFile(...)
                    //_output[i].root_spreadsheet_ = ROOT + "." + SPREADSHEET + "[" + i + "]";
                    //_output[i].parent_ref = root_ref_in; // ToDos: now!
                    //if (root_ref_in != null) _output[i].root_ref = root_ref_in;
                }
                else
                {
                    try {
                        _output[i] = (XS__spreadsheet) new XmlSerializer(typeof(XS__spreadsheet)).Deserialize(
                            OGen.Libraries.PresentationLayer.WebForms.Utilities.ReadURL(
                                filePath_in[i].ToString()
                                )
                            );
                    } catch (Exception _ex) {
                        throw new Exception(string.Format(
                                                System.Globalization.CultureInfo.CurrentCulture,
                                                "\n---\n{0}.{1}.Load_fromURI():\nERROR READING XML:\n{2}\n---\n{3}",
                                                typeof(XS__spreadsheet).Namespace,
                                                typeof(XS__spreadsheet).Name,
                                                //(filePath_in[i].IsFile)
                                                //	? filePath_in[i].LocalPath
                                                //	:
                                                filePath_in[i].ToString(),
                                                _ex.Message
                                                ));
                    }
                    _output[i].root_spreadsheet_ = ROOT + "." + SPREADSHEET + "[" + i + "]";
                    _output[i].parent_ref        = root_ref_in;              // ToDos: now!
                    if (root_ref_in != null)
                    {
                        _output[i].root_ref = root_ref_in;
                    }
                }
            }

            return(_output);
        }
Exemplo n.º 2
0
        public XS__RootMetadata(
                #endif
            string metadataFilePath_in
            )
        {
            string _metadataPath = System.IO.Path.GetDirectoryName(metadataFilePath_in);

            this.metadatafiles_ = Metadatas.Load_fromFile(metadataFilePath_in);

            #region int _total_xxx = ...;
            int _total_spreadsheet = 0;
            for (int f = 0; f < this.metadatafiles_.MetadataFiles.Count; f++)
            {
                switch (this.metadatafiles_.MetadataFiles[f].XMLFileType)
                {
                case XS__spreadsheet.SPREADSHEET:
                    _total_spreadsheet++;
                    break;
                }
            }
            #endregion
            #region string[] _xxxFilePath = new string[_total_xxx];
            string[] _spreadsheetFilePath = new string[
                _total_spreadsheet
                                            ];
            #endregion

            _total_spreadsheet = 0;
            for (int f = 0; f < this.metadatafiles_.MetadataFiles.Count; f++)
            {
                switch (this.metadatafiles_.MetadataFiles[f].XMLFileType)
                {
                case XS__spreadsheet.SPREADSHEET:
                    _spreadsheetFilePath[_total_spreadsheet] = System.IO.Path.Combine(
                        _metadataPath,
                        this.metadatafiles_.MetadataFiles[f].XMLFileName
                        );
                    _total_spreadsheet++;
                    break;
                }
            }

            this.spreadsheetcollection_ = new XS__spreadsheetCollection(
                XS__spreadsheet.Load_fromFile(
                    (XS__RootMetadata)this,
                    _spreadsheetFilePath
                    )
                );
        }
Exemplo n.º 3
0
        public static XS__spreadsheet[] Load_fromFile(
            XS__RootMetadata root_ref_in,
            params string[] filePath_in
            )
        {
            FileStream _stream;

            XS__spreadsheet[] _output
                = new XS__spreadsheet[filePath_in.Length];

            for (int i = 0; i < filePath_in.Length; i++)
            {
                _stream = new FileStream(
                    filePath_in[i],
                    FileMode.Open,
                    FileAccess.Read,
                    FileShare.Read
                    );

                try {
                    _output[i] = (XS__spreadsheet) new XmlSerializer(typeof(XS__spreadsheet)).Deserialize(
                        _stream
                        );
                    _stream.Close();
#if !NET_1_1
                    _stream.Dispose();
#endif
                } catch (Exception _ex) {
                    throw new Exception(string.Format(
                                            System.Globalization.CultureInfo.CurrentCulture,
                                            "\n---\n{0}.{1}.Load_fromFile():\nERROR READING XML:\n{2}\n---\n{3}\n---\n{4}\n---\n",
                                            typeof(XS__spreadsheet).Namespace,
                                            typeof(XS__spreadsheet).Name,
                                            filePath_in[i],
                                            _ex.Message,
                                            _ex.InnerException
                                            ));
                }
                _output[i].root_spreadsheet_ = ROOT + "." + SPREADSHEET + "[" + i + "]";

                _output[i].parent_ref = root_ref_in;                 // ToDos: now!
                if (root_ref_in != null)
                {
                    _output[i].root_ref = root_ref_in;
                }
            }
            return(_output);
        }
Exemplo n.º 4
0
		public static XS__spreadsheet[] Load_fromFile(
			XS__RootMetadata root_ref_in, 
			params string[] filePath_in
		) {
			FileStream _stream;
			XS__spreadsheet[] _output 
				= new XS__spreadsheet[filePath_in.Length];

			for (int i = 0; i < filePath_in.Length; i++) {
				_stream = new FileStream(
					filePath_in[i],
					FileMode.Open,
					FileAccess.Read,
					FileShare.Read
				);

				try {
					_output[i] = (XS__spreadsheet)new XmlSerializer(typeof(XS__spreadsheet)).Deserialize(
						_stream
					);
					_stream.Close();
#if !NET_1_1
					_stream.Dispose();
#endif
				} catch (Exception _ex) {
					throw new Exception(string.Format(
						System.Globalization.CultureInfo.CurrentCulture,
						"\n---\n{0}.{1}.Load_fromFile():\nERROR READING XML:\n{2}\n---\n{3}\n---\n{4}\n---\n",
						typeof(XS__spreadsheet).Namespace, 
						typeof(XS__spreadsheet).Name, 
						filePath_in[i],
						_ex.Message,
						_ex.InnerException
					));
				}
				_output[i].root_spreadsheet_ = ROOT + "." + SPREADSHEET + "[" + i + "]";

				_output[i].parent_ref = root_ref_in; // ToDos: now!
				if (root_ref_in != null) _output[i].root_ref = root_ref_in;
			}
			return _output;
		}
Exemplo n.º 5
0
		public XS__spreadsheetCollection(
		#endif
			XS__spreadsheet[] spreadsheetCollection_in
		) {
			this.spreadsheetcollection_ = spreadsheetCollection_in;
		}
Exemplo n.º 6
0
		public static XS__spreadsheet[] Load_fromURI(
			XS__RootMetadata root_ref_in, 
			params Uri[] filePath_in
		) {
			XS__spreadsheet[] _output 
				= new XS__spreadsheet[filePath_in.Length];

			for (int i = 0; i < filePath_in.Length; i++) {
				if (filePath_in[i].IsFile) {
					_output[i] = XS__spreadsheet.Load_fromFile(
						filePath_in[i].LocalPath
					)[0];
					// no need! everything's been taken care at: XS__spreadsheet.Load_fromFile(...)
					//_output[i].root_spreadsheet_ = ROOT + "." + SPREADSHEET + "[" + i + "]";
					//_output[i].parent_ref = root_ref_in; // ToDos: now!
					//if (root_ref_in != null) _output[i].root_ref = root_ref_in;
				} else {
					try {
						_output[i] = (XS__spreadsheet)new XmlSerializer(typeof(XS__spreadsheet)).Deserialize(
							OGen.lib.presentationlayer.webforms.utils.ReadURL(
								filePath_in[i].ToString()
							)
						);
					} catch (Exception _ex) {
						throw new Exception(string.Format(
							"\n---\n{0}.{1}.Load_fromURI():\nERROR READING XML:\n{2}\n---\n{3}",
							typeof(XS__spreadsheet).Namespace, 
							typeof(XS__spreadsheet).Name, 
							//(filePath_in[i].IsFile)
							//	? filePath_in[i].LocalPath
							//	: 
							filePath_in[i].ToString(),
							_ex.Message
						));
					}
					_output[i].root_spreadsheet_ = ROOT + "." + SPREADSHEET + "[" + i + "]";
					_output[i].parent_ref = root_ref_in; // ToDos: now!
					if (root_ref_in != null) _output[i].root_ref = root_ref_in;
				}
			}

			return _output;
		}
Exemplo n.º 7
0
		public static XS__spreadsheet DataTable_toXMLSpreadsheet(
			params DataTable[] dt_spreadsheet_in
		) {
			int _pageIndex;
			int _rowIndex;
			int _cellIndex;

			XS__spreadsheet _ss_output = new XS__spreadsheet();

			for (int s = 0; s < dt_spreadsheet_in.Length; s++) {
				_ss_output.PageCollection.Add(
					out _pageIndex,
					new XS_pageType()
				);
				_ss_output.PageCollection[_pageIndex].Name = dt_spreadsheet_in[s].TableName;

				_ss_output.PageCollection[_pageIndex].RowCollection.Add(
					out _rowIndex,
					new XS_rowType()
				);
				_ss_output.PageCollection[_pageIndex].RowCollection[_rowIndex].isHeader = true;
				for (int c = 0; c < dt_spreadsheet_in[s].Columns.Count; c++) {
					_ss_output.PageCollection[_pageIndex].RowCollection[_rowIndex].CellCollection.Add(
						out _cellIndex,
						new XS_cellType()
					);
					_ss_output.PageCollection[_pageIndex].RowCollection[_rowIndex].CellCollection[_cellIndex].Data
						= dt_spreadsheet_in[s].Columns[c].Caption;
				}

				bool _isEmpty;
				for (int r = 0; r < dt_spreadsheet_in[s].Rows.Count; r++) {
					_isEmpty = true;
					for (int c = 0; c < dt_spreadsheet_in[s].Columns.Count; c++) {
						if (dt_spreadsheet_in[s].Rows[r][c] != DBNull.Value) {
							_isEmpty = false;
						}
					}
					if (_isEmpty) continue;

					_ss_output.PageCollection[_pageIndex].RowCollection.Add(
						out _rowIndex,
						new XS_rowType()
					);
					_ss_output.PageCollection[_pageIndex].RowCollection[_rowIndex].isHeader = false;
					for (int c = 0; c < dt_spreadsheet_in[s].Columns.Count; c++) {
						_ss_output.PageCollection[_pageIndex].RowCollection[_rowIndex].CellCollection.Add(
							out _cellIndex,
							new XS_cellType()
						);
						if (dt_spreadsheet_in[s].Rows[r][c] != DBNull.Value) {
							_ss_output.PageCollection[_pageIndex].RowCollection[_rowIndex].CellCollection[_cellIndex].isNull = false;
							_ss_output.PageCollection[_pageIndex].RowCollection[_rowIndex].CellCollection[_cellIndex].Data
								= dt_spreadsheet_in[s].Rows[r][c].ToString();

						} else {
							_ss_output.PageCollection[_pageIndex].RowCollection[_rowIndex].CellCollection[_cellIndex].isNull = true;
							_ss_output.PageCollection[_pageIndex].RowCollection[_rowIndex].CellCollection[_cellIndex].Data
								= "";
						}
					}
				}

			}

			return _ss_output;
		} 
Exemplo n.º 8
0
		public XS__spreadsheetCollection(
			XS__spreadsheet[] spreadsheetcollection_in
		) : base (
			spreadsheetcollection_in
		) {
		}
Exemplo n.º 9
0
        public static XS__spreadsheet DataTable_toXMLSpreadsheet(
            params DataTable[] dt_spreadsheet_in
            )
        {
            int _pageIndex;
            int _rowIndex;
            int _cellIndex;

            XS__spreadsheet _ss_output = new XS__spreadsheet();

            for (int s = 0; s < dt_spreadsheet_in.Length; s++)
            {
                _ss_output.PageCollection.Add(
                    out _pageIndex,
                    new XS_pageType()
                    );
                _ss_output.PageCollection[_pageIndex].Name = dt_spreadsheet_in[s].TableName;

                _ss_output.PageCollection[_pageIndex].RowCollection.Add(
                    out _rowIndex,
                    new XS_rowType()
                    );
                _ss_output.PageCollection[_pageIndex].RowCollection[_rowIndex].IsHeader = true;
                for (int c = 0; c < dt_spreadsheet_in[s].Columns.Count; c++)
                {
                    _ss_output.PageCollection[_pageIndex].RowCollection[_rowIndex].CellCollection.Add(
                        out _cellIndex,
                        new XS_cellType()
                        );
                    _ss_output.PageCollection[_pageIndex].RowCollection[_rowIndex].CellCollection[_cellIndex].Data
                        = dt_spreadsheet_in[s].Columns[c].Caption;
                }

                bool _isEmpty;
                for (int r = 0; r < dt_spreadsheet_in[s].Rows.Count; r++)
                {
                    _isEmpty = true;
                    for (int c = 0; c < dt_spreadsheet_in[s].Columns.Count; c++)
                    {
                        if (dt_spreadsheet_in[s].Rows[r][c] != DBNull.Value)
                        {
                            _isEmpty = false;
                        }
                    }
                    if (_isEmpty)
                    {
                        continue;
                    }

                    _ss_output.PageCollection[_pageIndex].RowCollection.Add(
                        out _rowIndex,
                        new XS_rowType()
                        );
                    _ss_output.PageCollection[_pageIndex].RowCollection[_rowIndex].IsHeader = false;
                    for (int c = 0; c < dt_spreadsheet_in[s].Columns.Count; c++)
                    {
                        _ss_output.PageCollection[_pageIndex].RowCollection[_rowIndex].CellCollection.Add(
                            out _cellIndex,
                            new XS_cellType()
                            );
                        if (dt_spreadsheet_in[s].Rows[r][c] != DBNull.Value)
                        {
                            _ss_output.PageCollection[_pageIndex].RowCollection[_rowIndex].CellCollection[_cellIndex].IsNull = false;
                            _ss_output.PageCollection[_pageIndex].RowCollection[_rowIndex].CellCollection[_cellIndex].Data
                                = dt_spreadsheet_in[s].Rows[r][c].ToString();
                        }
                        else
                        {
                            _ss_output.PageCollection[_pageIndex].RowCollection[_rowIndex].CellCollection[_cellIndex].IsNull = true;
                            _ss_output.PageCollection[_pageIndex].RowCollection[_rowIndex].CellCollection[_cellIndex].Data
                                = "";
                        }
                    }
                }
            }

            return(_ss_output);
        }
Exemplo n.º 10
0
        public static void Main(string[] args)
        {
            #region string _ssFilePath = args[0];
            string _spreadSheetFilePath;
#if DEBUG
            if (args.Length != 1)
            {
                _spreadSheetFilePath = @"C:\Documents and Settings\Administrator\Desktop\TEST\Livro1.xlsx";
            }
            else
            {
                _spreadSheetFilePath = args[0];
            }
#else
            if (
                (args.Length != 1)
                )
            {
                Console.WriteLine("invalid argument!");
            }

            _ssFilePath = args[0];
            if (
                !System.IO.File.Exists(_ssFilePath)
                )
            {
                Console.WriteLine("file not found!");
            }
#endif
            #endregion

            #region DataTable[] _datatable = XS__spreadsheet.Spreadsheet_toDataTable(...);
            DataTable[] _datatable = XS__spreadsheet.Spreadsheet_toDataTable(
                _spreadSheetFilePath
                );
            if (_datatable == null)
            {
                return;
            }
            #endregion

            #region string _xmlFilePath = ...;
            string _xmlFilePath = System.IO.Path.Combine(
                System.IO.Path.GetDirectoryName(_spreadSheetFilePath),
                string.Format(
                    System.Globalization.CultureInfo.CurrentCulture,
                    "{0}.SpreadsheetXML.xml",
                    System.IO.Path.GetFileNameWithoutExtension(_spreadSheetFilePath)
                    )
                );
            #endregion
            XS__spreadsheet.DataTable_toXMLSpreadsheet(
                _datatable
                ).SaveState_toFile(
                _xmlFilePath
                );

#if DEBUG
            XS__spreadsheet _ss = XS__spreadsheet.Load_fromFile(
                _xmlFilePath
                )[0];
            for (int p = 0; p < _ss.PageCollection.Count; p++)
            {
                Console.WriteLine("--- {0}", _ss.PageCollection[p].Name);
                for (int r = 0; r < _ss.PageCollection[p].RowCollection.Count; r++)
                {
                    for (int c = 0; c < _ss.PageCollection[p].RowCollection[r].CellCollection.Count; c++)
                    {
                        Console.Write("{0}\t", _ss.PageCollection[p].RowCollection[r].CellCollection[c].Data);
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
#endif
        }