rislai
2024-06-21 e4724fcc72232d94e939d39a51234ce89b8c61e3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Quintiq file version 2.0
#parent: #root
Method Load (
  LocalTable localTable
) const
{
  TextBody:
  [*
    // rislai Jun-20-2024 (created)
    file := OSFile::Construct();
    recycleBin := localTable.RecycleBin();
    
    columns := selectset( localTable,LocalColumn,column,true );
    columnTree := NamedValueTree::Create();
    for( i := 0 ; i < columns.Size(); i++ ){
      column := columns.Element( i );
      tempHandle := columnTree.GetHandle( column.Name() );
      columnTree.Root().AddChild( tempHandle,i );
    }
    
    try {
      file.Open( this.FilePath(), "Read", false );
      webFileBinaryData := file.ReadBinary();
        
      generalExcelImportAndExportDataSource := GeneralExcelImportAndExportDataSource::Upload( recycleBin, webFileBinaryData, this.Name() );
      generalExcelImportAndExportDataSource.ReadStructure();
      selections := selectset( generalExcelImportAndExportDataSource, GeneralExcelImportAndExportDataTable, tempGEIAEDT, true );
      if( selections.Size() <> 0 ){
        table := selections.Element( 0 );
        generalColumns := selectset( table,GeneralExcelImportAndExportDataColumn,column,true );
        
        // 生成列数据
        for( i := 0; i< generalColumns.Size(); i++ ){
          generalColumn := generalColumns.Element( i );
          column := localTable.LocalColumn( relnew, Name := generalColumn.Name(),Index := generalColumn.ColumnIndex() );
          columns.Add( column );
          tempHandle := columnTree.GetHandle( column.Name() );
          columnTree.Root().AddChild( tempHandle,columns.Size() - 1 );
        }
        
        // 生成数据
        rowSize := table.GeneralExcelImportAndExportDataRow( relsize );
        for ( rowIndex := 0; rowIndex < rowSize; rowIndex++ ) {
          generalRow := select( table, GeneralExcelImportAndExportDataRow, tempGEIAEDR, tempGEIAEDR.RowNr() = rowIndex );
          row := localTable.LocalRow( relnew,Index := rowIndex );
          generalCells := selectsortedset( generalRow,GeneralExcelImportAndExportDataCell,cell,true,cell.GeneralExcelImportAndExportDataColumn().ColumnIndex() );
          
          traverse( generalCells,Elements,generalCell ){
            columnName := generalCell.GeneralExcelImportAndExportDataColumn().Name();
            columnHandle := columnTree.GetHandle( columnName );
            columnIndex := columnTree.Root().Child( columnHandle ).GetValueAsNumber();
            column := columns.Element( columnIndex );
            row.LocalCell( relnew,Value := generalCell.Value() ,LocalColumn := column );
          }
        }
      }
      // 后续删除
      generalExcelImportAndExportDataSource.Delete();
      file.Close();
    } onerror {
      if( not isnull( file )){
        file.Close(); 
      }
      error( e );
    }
  *]
}