View Javadoc
1   /*
2    * CSVeed (https://github.com/42BV/CSVeed)
3    *
4    * Copyright 2013-2023 CSVeed.
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of The Apache Software License,
8    * Version 2.0 which accompanies this distribution, and is available at
9    * https://www.apache.org/licenses/LICENSE-2.0.txt
10   */
11  package org.csveed.common;
12  
13  import java.util.Locale;
14  
15  /**
16   * The Class ColumnExcel.
17   */
18  public class ColumnExcel extends Column {
19  
20      /**
21       * Instantiates a new column excel.
22       *
23       * @param columnExcel
24       *            the column excel
25       */
26      public ColumnExcel(String columnExcel) {
27          super(excelColumnToColumnIndex(columnExcel));
28      }
29  
30      /**
31       * Excel column to column index.
32       *
33       * @param excelColumn
34       *            the excel column
35       *
36       * @return the int
37       */
38      private static int excelColumnToColumnIndex(String excelColumn) {
39          excelColumn = excelColumn.toUpperCase(Locale.getDefault());
40          int sum = 0;
41          for (int i = 0; i < excelColumn.length(); i++) {
42              char currentChar = excelColumn.charAt(i);
43              sum *= 26;
44              sum += currentChar - 'A' + 1;
45          }
46          return sum;
47      }
48  
49  }