Ȥ Blog

Ruby,C#

Java

Javaʣѥʸ̩˥ѡ롣

Javaʸѡɬפˤʤޤ org.apache.commons.lang.time.DateUtilsȤʣΥѥǻǤ뤽ʤΤǡѤƤäƤߤ롣
Ƥ˹碌 yyyy/MM/dd Ȥ yyyy.MM.dd Ȥ yyyy-MM-dd ȤŪ˻Ѥ줽ʤĤϥǥեȤб衢ȤפΤǤJavaʤΤǥϥʤԤϤƤޤ

ǡΤ褦ʥɤ񤤤Ƥߤޤ ڤʸ /(å, .(ɥåȡˡ-(ϥեˤȤʤ̤˻ѤǤѥǤ

	import java.text.ParseException;
	import java.util.Date;
	import org.apache.commons.lang.time.DateUtils;

	public class Main {
	    public static void main(String[] args) {

	        String[] patterns = new String[] {"yyyy-MM-dd", "yyyy.MM.dd", "yyyy/MM/dd"};

	        String[] dateStringList = new String[] {"1973-05-30", "1973.5.30", "1973/5/30", "1972/16/60"};

	        for (String dateString : dateStringList) {
	            try {
	                Date d = DateUtils.parseDate(dateString, patterns);
	                System.out.printf("String=%s, Date=%s\n", dateString, d);
	            } catch (ParseException e) {
	                // TODO Auto-generated catch block
	                e.printStackTrace();
	            }
	        }
	    }
	}
	
ǡ̤
53

󡢡 1972/16/60 Ȥꤨʤդ 1973/05/30
ȤȲᤷƤƤޤƤ顼ˤ衢ȤפΤǤޤθǤϤ⤦Τʤȡ⡼ɡ

Ǥ⡢DateUtils.parseDateStrictly Ȥȸ̩˲ᤷƤ뤽
ǡäƤߤȷ̤

05

ޤ줬̤Ȼפɡ

ʤߤC#Ǥϡ⤷ʤƤ̤ꡢ
43

ޤRubyǤ
55

C#RubyʤǤ

Java: POI IFؿǤ̤Ǥ뤫

ȡ롣

 50

23

Java POI ǴؿͤƤߤ

POIȤäƥΥǡɤ뤳ȤϤ狼äΤǤؿ̥ͤλͤϤɤʤ ºݤ٤δؿ仲ȤϰʤȻȤΤˤʤʤ

Ĵ٤Ƥߤȡ٤ΤϥݡȤƤ餷
  • References: single cell & area, 2D & 3D, relative & absolute
  • Literals: Number, text, boolean, error and array
  • Operators: arithmetic and logical, some region operators
  • Built-in functions: over 350 recognised, 280 evaluatable
  • Add-in functions: 3 from Analysis Toolpack
ȤꤢʬΤ褦Ǥ

FormulaEvaluator Ȥ饹ѰդƤơĤǷ׻̤ʤǤ褦Ǥ
ˡϤĤѰդƤΤǤȤꤢִñ

 FormulaEvaluator.evaluateInCell(Cell cell)

ȤäƤߤ롣ϰǻꤵ줿뤬׻ʤ餽η̤ǥ֤ƤޤޤʸμϼϷ̤Ǿ񤭤ˡ
Ǥʤʤ鲿ⵯޤ 
 Ȥꤢsum()ؿ̥ȤΥ򻲾Ȥ褦ʥեäƻƤߤޤ

 31
50
	public class Main {
		public static void main(String[] args){
		    try {
		        InputStream file = new FileInputStream("data/hello_poi.xls");
		        Workbook book = new HSSFWorkbook(file);
		        FormulaEvaluator feval = book.getCreationHelper().createFormulaEvaluator();
		        Sheet sheet = book.getSheetAt(0);
		        for(int rowIndex = 0; rowIndex < 4; rowIndex++) {
		            Row row = sheet.getRow(rowIndex);
		            for (int colIndex = 0; colIndex < 2; colIndex++) {
	                    Cell cell = row.getCell(colIndex);
	                    String rawValue = cell.toString();
	                    feval.evaluateInCell(cell);
	                    System.out.printf("row=%d, cell=%d, rawValue=%s, evaluatedValue=%s\n" ,
	                            rowIndex, 
	                            colIndex,
	                            rawValue,
	                            cell);
	                }
		        }
		        file.close();
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
		}
	}
  • row=2, cell=1, rawValue=Sheet2!A1, evaluatedValue=̥
  • row=3, cell=1, rawValue=SUM(D1:D3), evaluatedValue=6.0
ȼʬɾ줿̤ǤƤ褦Ǥ
줬ʤˤʤꤽäΤǡ䡼褫ä褫ä



28


JavaǥեɤǤߤ POIäƤʤ

ǶJavaǥե򰷤ɬפФƤơʹȤˤPOIȤΤȤ餷
POI100Javaǽ񤫤줿ޥեʤǺ줿ɥȤ򰷤饤֥ǡPOIȤ̾ˤ2Ťΰ̣Ƥ뤽Ǥ
ܤϲΥȤǡ


ǡ®ǿǤ3.7ɡ


EclipseǿץȤơPOI饤֥ӥɥѥɲá
05

ץѤΥե
55

եXMLǤϤʤ켰ΡʤȤǤǤŪʵxls¸
POIΤξΥեޥåȤбƤ褦Ǥ
59

åɤ򻲹ͤ˥ɤ񤤤Ƥߤ롣
ʤľŪ˰褦Ǥ
    1 import java.io.FileInputStream;
2 import java.io.InputStream;
3 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
4 import org.apache.poi.ss.usermodel.Row;
5 import org.apache.poi.ss.usermodel.Sheet;
6 import org.apache.poi.ss.usermodel.Workbook;
7
8
9 public class Main {
10 public static void main(String[] args){
11 try {
12 InputStream file = new FileInputStream("data/hello_poi.xls");
13 Workbook book = new HSSFWorkbook(file);
14 Sheet sheet = book.getSheetAt(0);
15 for(int rowIndex = 0; rowIndex < 2; rowIndex++) {
16 Row row = sheet.getRow(rowIndex);
17 System.out.printf("%s, %s\n", row.getCell(0), row.getCell(1));
18 }
19 file.close();
20 } catch (Exception e) {
21 e.printStackTrace();
22 }
23
}

24 }

25

¹ԤȤɽǤޤ
18

Ͻ񤭽ФäƤߤ롣



ץե

Ȥ

C#ɻŻRubyФʳȯԡ
ǶDockerȤؿȤAngularJS˥ϥޤäƤ롣
¢ȤĮȤȤ˽ס

QR
QR
  • 饤֥ɥ֥