Java Excel: Ajouter des textes dans un fichier Excel

Author:

 int,string,char,static, url, socket, url, socket, java
Download

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mesexemples;
 
import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
/**
 * Ajouter des textes dans un fichier Excel
 * @author mesexemples.com
 */
public class AddStringExcel 
{
        public static void main(String []args)throws Exception
    {
        // créer un nouveau fichier excel
        FileOutputStream out = new FileOutputStream("java_excel_texte.xls");
        // créer un classeur
        Workbook wb = new HSSFWorkbook();
        // créer une feuille
        Sheet mySheet = wb.createSheet();
 
        Cell myCel=null;
        // créer une ligne de à l'index 0 dans la feuille Excel
        Row myRow = null;      
        myRow = mySheet.createRow(0);
 
        // Les textes à ajouter dans le fichier Excel
        String texte_A1="Bienvenu";
        String texte_A2="Dans les exemples";
        String texte_A3="Excel pour Apache Poi";
 
        // Modifier la cellule 0 de la ligne
        myCel=myRow.createCell(0);
        myCel.setCellValue(texte_A1);
 
        // Modifier la cellule 1 de la ligne
        myCel=myRow.createCell(1);
        myCel.setCellValue(texte_A2); 
 
        // Modifier la cellule 2 de la ligne
        myCel=myRow.createCell(2);
        myCel.setCellValue(texte_A3);        
 
 
 
        wb.write(out);
 
        out.close();
    }
}

Cet article Java Excel: Ajouter des textes dans un fichier Excel est apparu en premier sur .