示例#1
0
 private void import_OnDataRowImported(object sender, ImportRowEventArg e)
 {
     if (this.ImportedHeader == null)
     {
         this.ImportedHeader = e.HeaderData;
     }
     if (this.ImportedData == null)
     {
         this.ImportedData = new List <List <object> >();
     }
     this.ImportedData.Add(e.RowData);
     e.IsSuccess = true;
 }
示例#2
0
        protected virtual SheetImportResult ImportSheet(ISheet sheet, SheetFormat format)
        {
            SheetImportResult result = new SheetImportResult();

            result.Name  = format.Name;
            result.Index = format.Index;
            int           dataColumnEnd;
            List <string> headerData = this.GetHeaderData(sheet, format, out dataColumnEnd);
            int           rowIndex   = format.DataRowStart;
            bool          isEnd      = false;
            IRow          dataRow    = sheet.GetRow(rowIndex);

            while (!isEnd && dataRow != null)
            {
                List <object>     rowData = this.GetRowData(dataRow, format, rowIndex, dataColumnEnd);
                ImportRowEventArg arg     = new ImportRowEventArg();
                arg.RowData    = rowData;
                arg.HeaderData = headerData;
                arg.Format     = format;
                arg.RowIndex   = rowIndex;
                if (this.OnDataRowImporting != null)
                {
                    this.OnDataRowImporting(this, arg);
                }
                if (arg.IsSkip)
                {
                    result.IncreaseSkiped();
                }
                else if (!string.IsNullOrEmpty(arg.Error))
                {
                    result.AddError(string.Format("第{0}处理失败:{1}", rowIndex, arg.Error));
                }
                else if (arg.IsSuccess)
                {
                    result.IncreaseSuccess();
                }
                isEnd = arg.IsEnd;
                if (!isEnd && format.AllEmptyIsEnd && rowData == null)
                {
                    isEnd = true;
                }
                if (!isEnd)
                {
                    rowIndex++;
                }
                dataRow = sheet.GetRow(rowIndex);
            }
            return(result);
        }