Skip to content

Commit b796c8d

Browse files
Update excelmerge.java
1 parent 418b55b commit b796c8d

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

excelmerge.java

+26-17
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11
package com.prad.test;
2-
import org.apache.poi.ss.usermodel.Cell;
3-
import org.apache.poi.ss.usermodel.Row;
42
import org.apache.poi.xssf.usermodel.XSSFSheet;
53
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
64
import java.util.*;
75
import java.io.*;
86
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
97
import org.apache.poi.ss.usermodel.*;
108
import java.io.FileOutputStream;
11-
import java.io.IOException;
12-
13-
import org.apache.poi.ss.usermodel.Cell;
14-
import org.apache.poi.ss.usermodel.CellStyle;
15-
import org.apache.poi.ss.usermodel.FillPatternType;
16-
import org.apache.poi.ss.usermodel.IndexedColors;
17-
import org.apache.poi.ss.usermodel.Row;
18-
import org.apache.poi.ss.usermodel.Sheet;
19-
import org.apache.poi.ss.usermodel.Workbook;
9+
import java.io.IOException;
2010

2111
public class excel_mrg {
2212
// Flags to control writing to Excel
2313
public static int rowNum = 1;
14+
public static int headerflag = 0;
2415
public static int cellcounter = 0;
2516

2617
public static Sheet sheet = null;
@@ -45,15 +36,17 @@ public static void main(String[] args) throws IOException, InvalidFormatExceptio
4536
try
4637
{
4738
Newworkbook = new XSSFWorkbook();
39+
headerStyleSetup();
40+
headerflag = 1;
4841
oldworkbook = new XSSFWorkbook(new FileInputStream(new File("/Users/pradeepp/Desktop/javasam/poi-generated-file.xlsx")));
4942
preProcessor();
5043

51-
44+
headerflag = 1;
5245
oldworkbook = new XSSFWorkbook(new FileInputStream(new File("/Users/pradeepp/Desktop/javasam/poi-generated-file1.xlsx")));
5346
preProcessor();
5447

55-
oldworkbook = new XSSFWorkbook(new FileInputStream(new File("/Users/pradeepp/Desktop/javasam/temp.xlsx")));
56-
preProcessor();
48+
// oldworkbook = new XSSFWorkbook(new FileInputStream(new File("/Users/pradeepp/Desktop/javasam/temp.xlsx")));
49+
// preProcessor();
5750

5851
FileOutputStream fileOut = new FileOutputStream("/Users/pradeepp/Desktop/javasam/rob_max.xlsx");
5952
Newworkbook.write(fileOut);
@@ -75,6 +68,17 @@ public static void preProcessor() {
7568
newTabProcessor();
7669
}
7770
}
71+
72+
public static void headerStyleSetup() {
73+
style = Newworkbook.createCellStyle();
74+
style.setFillForegroundColor(IndexedColors.AQUA.getIndex());
75+
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
76+
Font headerFont = Newworkbook.createFont();
77+
headerFont.setBold(true);
78+
headerFont.setFontHeightInPoints((short) 14);
79+
style.setFont(headerFont);
80+
}
81+
7882
public static void newTabProcessor() {
7983
Iterator<Row> rowIterator = sheet.iterator();
8084
while (rowIterator.hasNext())
@@ -102,9 +106,14 @@ public static void newTabProcessor() {
102106
NewcellRow.setCellValue(cell.getStringCellValue());
103107
break;
104108
}
105-
CellStyle newStyle = Newworkbook.createCellStyle();
106-
newStyle.cloneStyleFrom(cell.getCellStyle());
107-
NewcellRow.setCellStyle(newStyle);
109+
if(headerflag == 1) {
110+
CellStyle newStyle = Newworkbook.createCellStyle();
111+
newStyle.cloneStyleFrom(cell.getCellStyle());
112+
NewcellRow.setCellStyle(newStyle);
113+
headerflag=0;
114+
115+
}
116+
108117
}
109118
}
110119
}

0 commit comments

Comments
 (0)