1
1
package com .prad .test ;
2
- import org .apache .poi .ss .usermodel .Cell ;
3
- import org .apache .poi .ss .usermodel .Row ;
4
2
import org .apache .poi .xssf .usermodel .XSSFSheet ;
5
3
import org .apache .poi .xssf .usermodel .XSSFWorkbook ;
6
4
import java .util .*;
7
5
import java .io .*;
8
6
import org .apache .poi .openxml4j .exceptions .InvalidFormatException ;
9
7
import org .apache .poi .ss .usermodel .*;
10
8
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 ;
20
10
21
11
public class excel_mrg {
22
12
// Flags to control writing to Excel
23
13
public static int rowNum = 1 ;
14
+ public static int headerflag = 0 ;
24
15
public static int cellcounter = 0 ;
25
16
26
17
public static Sheet sheet = null ;
@@ -45,15 +36,17 @@ public static void main(String[] args) throws IOException, InvalidFormatExceptio
45
36
try
46
37
{
47
38
Newworkbook = new XSSFWorkbook ();
39
+ headerStyleSetup ();
40
+ headerflag = 1 ;
48
41
oldworkbook = new XSSFWorkbook (new FileInputStream (new File ("/Users/pradeepp/Desktop/javasam/poi-generated-file.xlsx" )));
49
42
preProcessor ();
50
43
51
-
44
+ headerflag = 1 ;
52
45
oldworkbook = new XSSFWorkbook (new FileInputStream (new File ("/Users/pradeepp/Desktop/javasam/poi-generated-file1.xlsx" )));
53
46
preProcessor ();
54
47
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();
57
50
58
51
FileOutputStream fileOut = new FileOutputStream ("/Users/pradeepp/Desktop/javasam/rob_max.xlsx" );
59
52
Newworkbook .write (fileOut );
@@ -75,6 +68,17 @@ public static void preProcessor() {
75
68
newTabProcessor ();
76
69
}
77
70
}
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
+
78
82
public static void newTabProcessor () {
79
83
Iterator <Row > rowIterator = sheet .iterator ();
80
84
while (rowIterator .hasNext ())
@@ -102,9 +106,14 @@ public static void newTabProcessor() {
102
106
NewcellRow .setCellValue (cell .getStringCellValue ());
103
107
break ;
104
108
}
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
+
108
117
}
109
118
}
110
119
}
0 commit comments