public DataReader(StructuredDataStructure structuredDatastructure, FileReaderInfo fileReaderInfo, IOUtility iOUtility, DatasetManager datasetManager) { DatasetManager = datasetManager; IOUtility = iOUtility; StructuredDataStructure = structuredDatastructure; Info = fileReaderInfo; ErrorMessages = new List <Error>(); Position = 1; }
public DataReader(StructuredDataStructure structuredDatastructure, FileReaderInfo fileReaderInfo, DatasetManager datasetManager) : this(structuredDatastructure, fileReaderInfo, new IOUtility(), datasetManager) { }
public DataReader(StructuredDataStructure structuredDatastructure, FileReaderInfo fileReaderInfo, IOUtility iOUtility) : this(structuredDatastructure, fileReaderInfo, iOUtility, new DatasetManager()) { }
/// <summary> /// Read a Excel row by row /// Convert the rows into a datatuple based on the datastructure. /// Return a list of datatuples /// </summary> /// <remarks></remarks> /// <seealso cref=""/> /// <param name="file">File as stream</param> /// <param name="fileName">Name of the file</param> /// <param name="fri">FileReaderInfo (ExcelFileReaderInfo) for additional Informations to read the file</param> /// <param name="sds">StructuredDataStructure of a dataset</param> /// <param name="datasetId">Datasetid of a dataset</param> /// <returns>List of DataTuples</returns> public List<DataTuple> ReadFile(Stream file, string fileName, FileReaderInfo fri, StructuredDataStructure sds, long datasetId) { this.FileStream = file; this.FileName = fileName; this.StructuredDataStructure = sds; this.Info = fri; this.DatasetId = datasetId; // Check params if (this.FileStream == null) { this.ErrorMessages.Add(new Error(ErrorType.Other, "File not exist")); } if (!this.FileStream.CanRead) { this.ErrorMessages.Add(new Error(ErrorType.Other, "File is not readable")); } if (this.Info.Variables <= 0) { this.ErrorMessages.Add(new Error(ErrorType.Other, "Startrow of Variable can´t be 0")); } if (this.Info.Data <= 0) { this.ErrorMessages.Add(new Error(ErrorType.Other, "Startrow of Data can´t be 0")); } if (this.ErrorMessages.Count == 0) { // open excel file spreadsheetDocument = SpreadsheetDocument.Open(this.FileStream, false); // get workbookpart WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart; SheetDimension dimension = workbookPart.WorksheetParts.First().Worksheet.GetFirstChild<SheetDimension>(); string s = dimension.Reference.Value; string[] references = s.Split(':'); // get all the defined area //List<DefinedNameVal> namesTable = BuildDefinedNamesTable(workbookPart); // Get intergers for reading data startColumn = GetColumnNumber(GetColumnName(references[0])); endColumn = GetColumnNumber(GetColumnName(references[1])); numOfColumns = (endColumn - startColumn) + 1; offset = this.Info.Offset; int endRowData = GetRowNumber(references[1]); // select worksheetpart by selected defined name area like data in sheet // sheet where data area is inside WorksheetPart worksheetPart = workbookPart.WorksheetParts.First(); //GetWorkSheetPart(workbookPart, this._areaOfData); // get styleSheet _stylesheet = workbookPart.WorkbookStylesPart.Stylesheet; // Get shared strings _sharedStrings = workbookPart.SharedStringTablePart.SharedStringTable.Elements<SharedStringItem>().ToArray(); if (GetSubmitedVariableIdentifier(worksheetPart, this.Info.Variables, this.Info.Variables) != null) { ReadRows(worksheetPart, this.Info.Data, endRowData); } return this.DataTuples; } return this.DataTuples; }
/// <summary> /// Read a Excel row by row /// Convert the rows into a datatuple based on the datastructure. /// Return a list of datatuples /// </summary> /// <remarks></remarks> /// <seealso cref=""/> /// <param name="file">File as stream</param> /// <param name="fileName">Name of the file</param> /// <param name="fri">FileReaderInfo (ExcelFileReaderInfo) for additional Informations to read the file</param> /// <param name="sds">StructuredDataStructure of a dataset</param> /// <param name="datasetId">Datasetid of a dataset</param> /// <returns>List of DataTuples</returns> public List <DataTuple> ReadFile(Stream file, string fileName, FileReaderInfo fri, StructuredDataStructure sds, long datasetId) { this.FileStream = file; this.FileName = fileName; this.StructuredDataStructure = sds; this.Info = fri; this.DatasetId = datasetId; // Check params if (this.FileStream == null) { this.ErrorMessages.Add(new Error(ErrorType.Other, "File not exist")); } if (!this.FileStream.CanRead) { this.ErrorMessages.Add(new Error(ErrorType.Other, "File is not readable")); } if (this.Info.Variables <= 0) { this.ErrorMessages.Add(new Error(ErrorType.Other, "Startrow of Variable can´t be 0")); } if (this.Info.Data <= 0) { this.ErrorMessages.Add(new Error(ErrorType.Other, "Startrow of Data can´t be 0")); } if (this.ErrorMessages.Count == 0) { // open excel file spreadsheetDocument = SpreadsheetDocument.Open(this.FileStream, false); // get workbookpart WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart; SheetDimension dimension = workbookPart.WorksheetParts.First().Worksheet.GetFirstChild <SheetDimension>(); string s = dimension.Reference.Value; string[] references = s.Split(':'); // get all the defined area //List<DefinedNameVal> namesTable = BuildDefinedNamesTable(workbookPart); // Get intergers for reading data startColumn = GetColumnNumber(GetColumnName(references[0])); endColumn = GetColumnNumber(GetColumnName(references[1])); numOfColumns = (endColumn - startColumn) + 1; offset = this.Info.Offset; int endRowData = GetRowNumber(references[1]); // select worksheetpart by selected defined name area like data in sheet // sheet where data area is inside WorksheetPart worksheetPart = workbookPart.WorksheetParts.First(); //GetWorkSheetPart(workbookPart, this._areaOfData); // get styleSheet _stylesheet = workbookPart.WorkbookStylesPart.Stylesheet; // Get shared strings _sharedStrings = workbookPart.SharedStringTablePart.SharedStringTable.Elements <SharedStringItem>().ToArray(); if (GetSubmitedVariableIdentifier(worksheetPart, this.Info.Variables, this.Info.Variables) != null) { ReadRows(worksheetPart, this.Info.Data, endRowData); } return(this.DataTuples); } return(this.DataTuples); }
public XmlDataReader() { Info = new FileReaderInfo(); Info.Decimal = DecimalCharacter.point; }