public void WriteRecord(JB64Value[] Data) { IRow TempRow = this.CurrSheet.CreateRow(this.CurrRow); this.CurrRow++; for (int x = 0; x < Data.Length; x++) { ICell TempCell = TempRow.CreateCell(x); if (Data[x].Type == "boolean") { TempCell.SetCellValue((bool)Data[x].Val); } else if (Data[x].Type == "integer" || Data[x].Type == "number") { Data[x].ConvertToNumber(); TempCell.SetCellValue((double)Data[x].Val); } else { if (Data[x].Type == "date") { Data[x] = new JB64Value(MainWizard.UTCToLocalDate((string)Data[x].Val), "date"); } if (Data[x].Type == "time") { Data[x] = new JB64Value(MainWizard.UTCToLocalTime((string)Data[x].Val), "time"); } Data[x].ConvertToString(); TempCell.SetCellValue((string)Data[x].Val); } } }
public JB64Value[] ReadRecord() { IRow RecordRow = this.CurrSheet.GetRow(this.CurrRowNum); this.CurrRowNum++; if (RecordRow == null) { return(null); } JB64Value[] Result = new JB64Value[this.NumCols]; for (int x = 0; x < this.NumCols; x++) { ICell TempRecordCell = RecordRow.GetCell(RecordRow.FirstCellNum + x); if (TempRecordCell == null) { Result[x] = new JB64Value(""); } else if (TempRecordCell.CellType == CellType.Boolean) { Result[x] = new JB64Value(TempRecordCell.BooleanCellValue); } else if (TempRecordCell.CellType == CellType.Numeric) { Result[x] = new JB64Value(TempRecordCell.NumericCellValue); } else { Result[x] = new JB64Value(TempRecordCell.StringCellValue); } } return(Result); }
public SetOptionsEntry(string Name, string OrigType, JB64Value OrigVal, bool Enabled) { this.Name = Name; this.OrigType = OrigType; this.OrigVal = OrigVal; this.Type = OrigType; this.Enabled = Enabled; }
public List <SetOptionsEntry[]> GetSetOptionsEntryList(bool AllowBinary) { List <SetOptionsEntry[]> SetOptionsEntries = new List <SetOptionsEntry[]>(); foreach (ISheet TempSheet in Workbook) { // Get the headers and first record. if (TempSheet.FirstRowNum >= 0) { IRow HeaderRow = TempSheet.GetRow(TempSheet.FirstRowNum); IRow RecordRow = TempSheet.GetRow(TempSheet.FirstRowNum + 1); if (HeaderRow != null && RecordRow != null) { SetOptionsEntries.Add(new SetOptionsEntry[HeaderRow.LastCellNum - HeaderRow.FirstCellNum]); int y = HeaderRow.LastCellNum - HeaderRow.FirstCellNum; for (int x = 0; x < y; x++) { ICell TempHeaderCell = HeaderRow.GetCell(HeaderRow.FirstCellNum + x); ICell TempRecordCell = RecordRow.GetCell(RecordRow.FirstCellNum + x); string HeaderName = (TempHeaderCell == null ? "" : TempHeaderCell.StringCellValue); JB64Value Result; if (TempRecordCell == null) { Result = new JB64Value(""); } else if (TempRecordCell.CellType == CellType.Boolean) { Result = new JB64Value(TempRecordCell.BooleanCellValue); } else if (TempRecordCell.CellType == CellType.Numeric) { Result = new JB64Value(TempRecordCell.NumericCellValue); } else { Result = new JB64Value(TempRecordCell.StringCellValue); } SetOptionsEntries[SetOptionsEntries.Count - 1][x] = new SetOptionsEntry(HeaderName, Result.Type, Result, true); } } } } return(SetOptionsEntries); }
private string SetOptions_GetDisplayValue(JB64Value Val, string Type) { if (Val.Type == "number") { if (Type == "date") { Val = new JB64Value(ExcelDateToUTC((double)Val.Val)); } else if (Type == "date-alt") { Val = new JB64Value(ExcelDateToLocal((double)Val.Val)); } else if (Type == "time") { Val = new JB64Value(ExcelTimeToUTC((double)Val.Val)); } else if (Type == "time-alt") { Val = new JB64Value(ExcelTimeToLocal((double)Val.Val)); } else { Val = new JB64Value(Val); } } else { Val = new JB64Value(Val); } Val.ConvertTo(Type.Replace("-alt", "")); Val.ConvertToString(); string Val2 = (string)Val.Val; if (Type == "boolean") { Val2 = (Val2 == "0" ? "false" : "true"); } if (Val2.Length > 50) { Val2 = Val2.Substring(0, 50) + "..."; } return(Val2); }
private void RunConversion(object sender, DoWorkEventArgs e) { BackgroundWorker TempWorker = (BackgroundWorker)sender; int RecordNum = 1; bool NullAllowed = this.WriteConvert.IsNullAllowed(); SetOptionsEntry[] TempOptionsEntry = this.SetOptionsEntries[this.SetOptionsActiveEntry]; while (!this.ReadConvert.EndOfRecords()) { if (TempWorker.CancellationPending) { this.AllowNext = false; break; } // Read in a record. try { JB64Value[] TempRecord = this.ReadConvert.ReadRecord(); // Transform the record. try { for (int x = 0; x < TempRecord.Length; x++) { if (TempOptionsEntry[x].Enabled) { if (!NullAllowed) { TempRecord[x].ConvertToNotNull(TempOptionsEntry[x].Type); } if (TempOptionsEntry[x].OrigType == "number") { if (TempOptionsEntry[x].Type == "date") { TempRecord[x] = new JB64Value(ExcelDateToUTC((double)TempRecord[x].Val)); } else if (TempOptionsEntry[x].Type == "date-alt") { TempRecord[x] = new JB64Value(ExcelDateToLocal((double)TempRecord[x].Val)); } else if (TempOptionsEntry[x].Type == "time") { TempRecord[x] = new JB64Value(ExcelTimeToUTC((double)TempRecord[x].Val)); } else if (TempOptionsEntry[x].Type == "time-alt") { TempRecord[x] = new JB64Value(ExcelTimeToLocal((double)TempRecord[x].Val)); } } TempRecord[x].ConvertTo(TempOptionsEntry[x].Type.Replace("-alt", "")); } } // Write the record. try { this.WriteConvert.WriteRecord(TempRecord); } catch (Exception) { this.ConversionResults += "Record #" + RecordNum + ": Error writing the record.\r\n"; } } catch (Exception) { this.ConversionResults += "Record #" + RecordNum + ": Error transforming the record.\r\n"; } } catch (Exception) { this.ConversionResults += "Record #" + RecordNum + ": Error reading the record.\r\n"; } RecordNum++; int Percent = this.ReadConvert.PercentRead(); TempWorker.ReportProgress(Percent, Percent.ToString() + "%"); } this.WriteConvert.Close(); this.ConversionResults += "Conversion completed.\r\n"; }