ÃֽŠ°Ô½Ã±Û(JAVA)
2018.06.29 / 21:54

Jakarta POI - ¾²±â

aichatbot
Ãßõ ¼ö 251

III. Formula(¼ö½Ä) Áö¿ø

¿¢¼¿À» ÀÐ°í ¾µ¶§ ¼ö½ÄÀ» Áö¿øÇÕ´Ï´Ù. 
org.apache.poi.hssf.usermodel.HSSFCellÀÇ setCellFormula("formulaString") ¸Þ½îµå´Â ½ºÇÁ·¹µå½ÃÆ®¿¡ ¼ö½ÄÀ» Ãß°¡Çϴµ¥ »ç¿ëµÇ¸ç getCellFormula() ¸Þ½îµå´Â ¼ö½ÄÀ» ´ëÇ¥ÇÏ´Â ¹®ÀÚ¿­À» Çؼ®Çϴµ¥ »ç¿ëµË´Ï´Ù. ÇÏÁö¸¸ ¿¢¼¿¿¡¼­ »ç¿ëÇÏ´Â ¼ö½ÄÀ» ¸ðµÎ »ç¿ë ÇÒ ¼ö´Â ¾ø½À´Ï´Ù.

 

¨ç Áö¿øµÇ´Â ºÎºÐ
-. ¼¿ ÂüÁ¶, ½ÃÆ®ÂüÁ¶, Áö¿ªÂüÁ¶
-. »ó´ëÀû ȤÀº Àý´ëÀû ÂüÁ¶ 
-. ¼ö¿¬»ê ¹× ³í¸®¿¬»ê
-. ½ÃÆ® ȤÀº ¸ÅÅ©·Î ÇÔ¼ö

-. ¼ö½Ä °á°ú°ª ¹Ýȯ

 

¨è ºÎºÐÀû Áö¿ø
¹®ÀÚ¿­À» Æ÷ÇÔÇÏ´Â ¼ö½ÄÀ» Çؼ®ÇÒ ¼ö´Â ÀÖÁö¸¸ ¹®ÀÚ¿­°ªÀ» ¹ÝȯÇÏ´Â ¼ö½ÄÀº ¾ÆÁ÷ Áö¿øÇÏÁö ¾Ê½À´Ï´Ù.

¨é Áö¿øµÇÁö ¾Ê´Â ºÎºÐ

-. ¹è¿­ ¼ö½Ä 
-. 1Áø¹ý ¼ö½Ä
-. 3D ÂüÁ¶
-. ¿¡·¯ °ª (cells containing #REF's or #VALUE's)


VII. ¿¢¼¿ ¾²±â¿¹Á¦

¾²±âµµ ¿ª½Ã Àбâ¿Í ºñ½ÁÇÕ´Ï´Ù.

¨ç ¿¢¼¿ ¿öÅ©ºÏÀ» »ý¼ºÇÕ´Ï´Ù. Çà°ú ¼¿À» »ý¼ºÇÏ·Á¸é ´ç¿¬ÇÑ ÀýÂ÷°ÚÁÒ?

HSSFWorkbook workbook = new HSSFWorkbook();

¨è ½ÃÆ®¸¦ »ý¼ºÇÕ´Ï´Ù.

½ÃÆ®¸íÀ» ÆĶó¹ÌÅÍ·Î ¹Ù·Î »ý¼º ÇÕ´Ï´Ù.

HSSFSheet sheet = workbook.createSheet("sheet name");

¸¸¾à Çѱ۷Π½ÃÆ®¸íÀ» ¸¸µé·Á¸é ´ÙÀ½°ú °°ÀÌ ÀÎÄÚµùÀÌ ÇÊ¿äÇÕ´Ï´Ù.

HSSFSheet sheet = workbook.createSheet();
workbook.setSheetName( 0 , "ÇѱÛ" , HSSFWorkbook.ENCODING_UTF_16 );

¨é ¼¿¿¡ »ç¿ëÇÒ ½ºÅ¸ÀÏÀ» ¹Ì¸® »ý¼ºÇØ µÓ´Ï´Ù.

HSSFCellStyle style = wb.createCellStyle();
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style.setBottomBorderColor(HSSFColor.BLACK.index);
style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
style.setLeftBorderColor(HSSFColor.GREEN.index);
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
style.setRightBorderColor(HSSFColor.BLUE.index);
style.setBorderTop(HSSFCellStyle.BORDER_MEDIUM_DASHED);
style.setTopBorderColor(HSSFColor.BLACK.index);

µî ¿©·¯°¡Áö ½ºÅ¸ÀÏÀ» ¸¸µé ¼ö ÀÖ½À´Ï´Ù.

½ºÅ¸ÀÏÀº ´ÙÀ½ ÁÖ¼Ò¸¦ Âü°íÇϼ¼¿ä
http://jakarta.apache.org/poi/apidocs/org/apache/poi/hssf/usermodel/HSSFCellStyle.html

¨ê ·Î¿ì¸¦ Çϳª »ý¼ºÇÕ´Ï´Ù.

HSSFRow row = sheet.createRow(0);

¨ë ¼¿Ãú Çϳª »ý¼ºÇÏ¿© ½ºÅ¸ÀÏÀ» ÁÖ°í °ªÀ» ÀÔ·ÂÇÕ´Ï´Ù.

HSSFCell cell = row.createCell((short)0);
cell.setCellStyle(style);
cell.setCellValue("jakarta project!");

¸¸¾à ÇѱÛÀ» ÀÔ·ÂÇÑ´Ù¸é ÀÎÄÚµù ÇØ¾ß ÇÏ¸ç °ª ¼¼ÆÃÀü¿¡ ÇØ¾ß ÇÕ´Ï´Ù.

cell.setEncoding(HSSFCell.ENCODING_UTF_16);  //ÇÑ±Û Ã³¸®
cell.setCellStyle(style);
cell.setCellValue("ÀÚÄ«µåŸ ÇÁ·ÎÁ§Æ®!");

¨ì ¸ðµç ¼¿ÀÌ ´Ù ÀԷµǾúÀ¸¸é ÆÄÀÏÀ» ¸¸µì´Ï´Ù.

FileOutputStream fs = new FileOutputStream("excelfile.xls");
workbook.write(fs);
fs.close();

VIII. ¾²±â»ùÇà ¼Ò½º

<%@ page language="java" contentType="text/html;charset=euc-kr" %>
<%@ page import="java.io.*" %>
<%@ page import="org.apache.poi.poifs.dev.*" %>
<%@ page import="org.apache.poi.hssf.record.*" %>
<%@ page import="org.apache.poi.hssf.record.formula.*" %>
<%@ page import="org.apache.poi.hssf.model.*" %>
<%@ page import="org.apache.poi.hssf.usermodel.*" %>
<%@ page import="org.apache.poi.hssf.util.*" %>


<html>
<body>

<%

    String filepath = "C:\\Tomcat 5.0\\webapps\\ROOT\\write.xls";


    try {

        String[] cell_value = {"ÀÚÄ«¸£Å¸","ÇÁ·ÎÁ§Æ®","www.jakartaproject.com"};


        HSSFWorkbook workbook = new HSSFWorkbook();


        HSSFSheet sheet = workbook.createSheet();
        workbook.setSheetName(0 , "Çѱ۸í" ,HSSFWorkbook.ENCODING_UTF_16);


        HSSFCellStyle style = workbook.createCellStyle();
        style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        style.setBottomBorderColor(HSSFColor.BLACK.index);
        style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        style.setLeftBorderColor(HSSFColor.GREEN.index);
        style.setBorderRight(HSSFCellStyle.BORDER_THIN);
        style.setRightBorderColor(HSSFColor.BLUE.index);
        style.setBorderTop(HSSFCellStyle.BORDER_MEDIUM_DASHED);
        style.setTopBorderColor(HSSFColor.BLACK.index);           


        HSSFRow row = sheet.createRow(0);
        for (int i = 0 ; i < cell_value.length; i++){
            HSSFCell cell = row.createCell((short)i);
            cell.setEncoding(HSSFCell.ENCODING_UTF_16); 
            cell.setCellStyle(style);
            cell.setCellValue(cell_value[i]);
        }
            
        FileOutputStream fs = null;
        try { 
            fs = new FileOutputStream(filepath);
            workbook.write(fs);
        } catch (Exception e) {
        } finally {
            if (fs != null) fs.close();
        }
        
    } catch (Exception e) {
%> 
        Error occurred:  <%= e.getMessage() %>
<%   
        e.printStackTrace();
    }    
    
%>

</body>
</html>


ÀÚ °á°úÈ­¸é ÀÔ´Ï´Ù.

»ç¿ëÀÚ »ðÀÔ À̹ÌÁö



¼º°ø!
À§ÀÇ ¼Ò½º¸¦ ±âº»À¸·Î ÇÑ´Ù¸é ±×¸® ¾î·ÆÁö ¾ÊÀ»°Ì´Ï´Ù ^^

Âü°í·Î ¼¿º´ÇÕÀº

HSSFWorkbook wb = new HSSFWorkbook(); 
HSSFSheet sheet = wb.createSheet("new sheet"); 

HSSFRow row = sheet.createRow((short) 1); 
HSSFCell cell = row.createCell((short) 1); 
cell.setCellValue("This is a test of merging"); 

//¼¿º´ÇÕ 
//Region(int ½ÃÀÛrow, short ½ÃÀÛcol, int Á¾·árow, short Á¾·ácol) 
sheet.addMergedRegion(new Region(1,(short)1,1,(short)2)); 

FileOutputStream fileOut = new FileOutputStream("workbook.xls"); 
wb.write(fileOut); 
fileOut.close(); 

¿Í °°ÀÌÇÏ¸é µË´Ï´Ù.