Schrift in Excelliste vertikal anzeigen und Zellen verbinden

Status
Nicht offen für weitere Antworten.

Floyd334

Neues Mitglied
Hallo,

Ich habe eine Excel-Datei via POI erstellt und will nun die Überschrift vertikal anzeigen.

Desweiteren sollen in einer Folgezeile bestimmte Spalten miteinander verbunden werden.

Folgendes Coding im Anfangsstadium habe ich derzeit, es folgt noch die Ausgabe und das Einstellen der Daten einer DB.

Leider funktioniert die Anzeige vertikal bei "cell0" nicht. Der Text wird nur mittig angeordnet aber nicht vertikal.

Hat jemand einen Tip was ich falsch mache?

Code:
package liste;

import java.io.FileOutputStream;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;


public class Excelliste{


	public static void main(String[] args)
	{
		try
		{

		        HSSFWorkbook wb = new HSSFWorkbook();
 	  	 	HSSFSheet sheet1 = wb.createSheet("Antragsübersicht");
 	  	 	
 	 
 	 		HSSFCellStyle style = wb.createCellStyle();
			

			style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);		
			 	 
 	  	 	
    		        HSSFRow row = sheet1.createRow((short)0);  // Create a row and put some cells in it. Rows are 0   
                        based.		 
  			
    		
    		        HSSFCell cell0 = row.createCell((short)0);  // Create a cell and put a value in it.
 
    		        cell0.setCellValue("Zweigstelle");
 
 			cell0.setCellStyle(style);
  
    		 	
 			HSSFCell cell1 = row.createCell((short)1); 
    		        cell1.setCellValue("Bündel-PHV");
 	  	 	
 	  	 	HSSFCell cell2 = row.createCell((short)2); 
    		        cell2.setCellValue("Bündel-VHV/VGV");
    		
    		        HSSFCell cell3 = row.createCell((short)3); 
    		        cell3.setCellValue("Gebäude");
    		
    		        HSSFCell cell4 = row.createCell((short)4); 
    		        cell4.setCellValue("Hausrat");
    		
    		        HSSFCell cell5 = row.createCell((short)5); 
    		        cell5.setCellValue("Kraftfahrt");
    		
    		        HSSFCell cell6 = row.createCell((short)6); 
    		        cell6.setCellValue("Privathaftpflicht");
    		
    		        HSSFCell cell7 = row.createCell((short)7); 
    		        cell7.setCellValue("Unfall");
    		
    		        HSSFCell cell8 = row.createCell((short)8); 
    		        cell8.setCellValue("Zwischensumme Komposit");
    		
    		        HSSFCell cell9 = row.createCell((short)9); 
    		        cell9.setCellValue("Kapitalleben");
    		
    		        HSSFCell cell10 = row.createCell((short)10); 
    		        cell10.setCellValue("Rentenversicherrung");
   
       		        HSSFCell cell11 = row.createCell((short)11); 
    		        cell11.setCellValue("Risikoleben");
   
       		        HSSFCell cell12 = row.createCell((short)12); 
    		        cell12.setCellValue("S-PrivatRente");
   
       		        HSSFCell cell13 = row.createCell((short)13); 
    		        cell13.setCellValue("Sterbegeld");
   
       		        HSSFCell cell14 = row.createCell((short)14); 
    		        cell14.setCellValue("Zwischensumme Leben");
   
       		        HSSFCell cell15 = row.createCell((short)15); 
    		        cell15.setCellValue("Restkredit");
   
       		        HSSFCell cell16 = row.createCell((short)16); 
    		        cell16.setCellValue("Gesamt");
       		
 	  	 	
 	  	 	
 	  	        FileOutputStream fileOut = new FileOutputStream("X:/Geraldy/TestExcelliste.xls");
  		        wb.write(fileOut);
    		        fileOut.close();    		
    		
    		
    		
		}
		catch(Exception e)
		{
		}                    

	}


}

Vorab vielen Dank.

LG

Floyd


L-ectron-X hat Code-Tags gesetzt.
 
G

Guest

Gast
Hatte ein ähnliches Prob.
Und zwar wollte ich die zusammengesetzten Zeilen / Spalten mit auslesen...
dazu folgender Snippet:

Code:
public static List<List<Object>> read(String path) {
		 // Liste mit den Zelleninhalten
        List<List<Object>> listContent = new ArrayList<List<Object>>();
		try {
			File ExcelFile = new File(path);
	        // Erstellen eines org.apache.poi.poifs.filesystem.Filesystem
	        FileInputStream fis = new FileInputStream(ExcelFile);
	        POIFSFileSystem poifs = new POIFSFileSystem(fis);
	        
	        // SimpleDateFormat fuer die Umwandlung von Date-Objekten in Strings
	        SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
	        
	        // Einlesen des Workbooks
	        HSSFWorkbook workbook = new HSSFWorkbook(poifs);
	        // Holen des Sheets (Es wird in diesem Beispiel nur das erste Sheet ausgelesen)
	        HSSFSheet sheet = workbook.getSheetAt(0);
	        int i=1;
	        // Einlesen der einzelnen Zellen
			for (Iterator rit = sheet.rowIterator(); rit.hasNext(); ) {
		            HSSFRow row = (HSSFRow)rit.next();
		            List<Object> listRow = new ArrayList<Object>();
		            for (Iterator cit = row.cellIterator(); cit.hasNext(); ) {
		                HSSFCell cell = (HSSFCell)cit.next();
  
		                switch (cell.getCellType()) {
		                    // Einlesen eines Nummernwertes od. eines Datumswertes
		                    case HSSFCell.CELL_TYPE_NUMERIC: 
		                        // pruefen ob es sich um einen Datumswert handelt
		                        if (HSSFDateUtil.isCellDateFormatted(cell)) {
		                            listRow.add(sdf.format(cell.getDateCellValue()));
		                        }
		                        // wenn kein Datumsfeld als Number auslesen
		                        else {
		                            listRow.add(Double.toString(cell.getNumericCellValue()));
		                        }
		                        break;
		                    // Einlesen eines Stringwertes
		                    case HSSFCell.CELL_TYPE_STRING:
		                        listRow.add(cell.getRichStringCellValue().getString());
		                        break;
                                   // Hier kommen die Leeren (zusammengestzten) durch
		                    case HSSFCell.CELL_TYPE_BLANK:
		                    	listRow.add("LEER");
		                        break;
		                    // Alle anderen Zeilen werden ignoriert
		                    default: break;
		                }
		            }
		            listContent.add(listRow);
			}
	        // Schliessen des InputStreams
	        fis.close();
		}
		catch (Exception e) {
            e.printStackTrace();
        }
		return listContent;
	}

Viel Erfolg an den der's brauch
 
Status
Nicht offen für weitere Antworten.

Neue Themen


Oben