CP1251

var version = java.lang.System.getProperty("java.version");
if (version.startsWith("1.8.0")) {
    load("nashorn:mozilla_compat.js");
}

importPackage(java.io);
importPackage(org.apache.poi.hssf.usermodel);
importPackage(org.apache.poi.hssf.util);
importPackage(org.apache.poi.ss.usermodel);
importPackage(org.apache.log4j);
logger = LogManager.getLogger("Logger");

logger.debug("================ loading Excel file =====================");
// имя файла передаем через глобальную переменную
file = GLOBAL.get('FILE');
logger.debug("file name: [" + file + "]");
if (file == null) shit.happens();


try {  wb = WorkbookFactory.create(new File(file)); }
catch (e)
{
  logger.debug('================ Error opening file: =================== ');
  logger.debug(e);
  shit.happens();
}

sheet = wb.getSheetAt(0);
ri = sheet.rowIterator();
i = 0;
file = GLOBAL.put('EXCEL_LOAD', 0);
while(true)
{
  try { row = ri.next(); } catch(e) { break ;}
  if (row.getCell(1) != null && row.getCell(1).toString().length() > 0 && row.getCell(1).toString() != "Артикул")
  {
    
    file = GLOBAL.put('EXCEL_LOAD', 1);
    logger.debug("[" + row.getCell(0) + "]  [" + row.getCell(1) + "]  [" + row.getCell(2) + "] [" + row.getCell(3) + "]  [" + row.getCell(4) + "] [" + row.getCell(5) + "]");
    logger.debug("types: [" + ((row.getCell(0)==null)?"null":row.getCell(0).getCellType()) +
                      "] [" + ((row.getCell(1)==null)?"null":row.getCell(1).getCellType()) +
                      "] [" + ((row.getCell(2)==null)?"null":row.getCell(2).getCellType()) +
                      "] [" + ((row.getCell(3)==null)?"null":row.getCell(3).getCellType()) +
                      "] [" + ((row.getCell(4)==null)?"null":row.getCell(4).getCellType()) +
                      "] [" + ((row.getCell(5)==null)?"null":row.getCell(5).getCellType()) + "]");

    if ( ((row.getCell(1)==null)?"null":row.getCell(1).getCellType()) == 0 ) logger.debug("getNumericCellValue: [" + row.getCell(1).getNumericCellValue() + "]");

    
    D_SPC.newRow();
    D_SPC.setValue ('spc.id_active', row.getCell(1).getNumericCellValue().toString());
    D_SPC.setValue ('active.name_active', row.getCell(3));
    D_SPC.setValue ('spc.price1_spc', row.getCell(4));
    //if (row.getCell(3) != null && row.getCell(3).toString().length() > 0) GRIDDS2.setValue ('barcode', row.getCell(3).getNumericCellValue().toString());
    i ++;
  }
}

D_SPC.notifyViews();



