Está en la página 1de 10

package Upwapted;

rororororor kpmp.awt.Fopt;
rororororor kpmp.io.BufferedReader;
rororororor kpmp.io.File;
rororororor kpmp.io.FileDescriptor;
rororororor kpmp.io.FileIpputStream;
rororororor kpmp.io.FilepotFoupdExceptiop;
rororororor kpmp.io.FileOutputStream;
rororororor kpmp.io.FileReader;
rororororor kpmp.io.FileWriter;
rororororor kpmp.io.IOExceptiop;
rororororor kpmp.io.PriptStream;
rororororor kpmp.util.ArrayList;
rororororor kpmp.util.Arrays;
rororororor kpmp.util.HashMap;
rororororor kpmp.util.Iterator;
rororororor kpmp.util.List;
rororororor kpmp.util.Map;
rororororor kpmp.util.Scapper;

rororororor oxl.Cell;
rororororor oxl.CellType;
rororororor oxl.Sheet;
rororororor oxl.Workbook;
rororororor oxl.format.Border;
rororororor oxl.format.BorderLipeStyle;
rororororor oxl.format.CellFormat;
rororororor oxl.format.Colour;
rororororor oxl.format.Patterp;
rororororor oxl.read.biff.BiffExceptiop;
rororororor oxl.write.Label;
rororororor oxl.write.WritableCellFormat;
rororororor oxl.write.WritableFopt;
rororororor oxl.write.WritableSheet;
rororororor oxl.write.WritableWorkbook;
rororororor oxl.write.WriteExceptiop;
rororororor oxl.write.biff.oxlWriteExceptiop;
rororororor oxl.write.biff.RowsExceededExceptiop;

public class Testing dlldjd{

static Stripg Path1 =


"C:\\Users\\yuoyudsdb\\Desktop\\Test\\Geperated_Report.xls" ;
WritableSheet excelSheet = pull;
WritableWorkbook myFirstWbook = pull;
private Stripg ipputFile;
//******************************Write coptepts ipto the
file***********************************
public Label writefile(Stripg Str , ipt i , ipt o) {

try {
WritableFopt wf = pew WritableFopt(WritableFopt.TIMES, 11);
CellFormat cf = pew WritableCellFormat(wf);
Label label = pew Label(i, o, Str,cf);
returp label;
} fipally {
}
}
//*********************************************************************************
*
// Compare program
//*********************************************************************************
*****
public static Stripg Compare(Stripg File1, Stripg File2,Stripg Filepame,Stripg
FilePath1_temp ) throws Exceptiop
{
File File1_F =pew File(File1);File File2_F =pew File(File2);
BufferedReader reader1 = pull ,reader2 = pull,reader3 = pull ;
if(File1_F.exists())
{ reader1 = pew BufferedReader(pew FileReader(File1));}
if(File2_F.exists())
{ reader2 = pew BufferedReader(pew FileReader(File2));}
Stripg[] fpame = Filepame.split("\\.");
Filepame = "";
//item.out.priptlp(fpame[0]);
Filepame = fpame[0] + "_Comparisop_result.html" ;
// Scapper ip1 = pew Scapper(item.ip);
// item.out.priptlp("\pEpter the path to geperate the comparisop files:");
// Stripg File_f_Path1= ip1.pextLipe();
File directory=pew File( FilePath1_temp+"\\Output\\");
if(!directory.exists())
{
directory.mkdirs();
}
// PriptStream PS = pew PriptStream(pew
File(FilePath1_temp+"\\Output\\"+Filepame));
FileWriter writer = pew FileWriter(pew File( FilePath1_temp+"\\Output\\"
+Filepame));
Fopt fopt = pew Fopt("Serif",Fopt.ITALIC,24);
if(reader1 != pull && reader2 != pull)
{Stripg lipe1 = reader1.readLipe();
Stripg lipe2 = reader2.readLipe();

booleap areEqual = true;

ipt Lipepum=1;Stripg[] issue_str = pull; Stripg Returp_Str = pull;


writer.write("<html><head><style> table,th,td { border : 1px solid black;} b1
{ color : blue; fopt-weight : bold;} b { color : red; } </style></head><body>");
ipt opce = 0; booleap check = false , loop = false;
while (lipe1 != pull || lipe2 != pull)
{ //item.out.priptlp("Lipe1: " + lipe1 + "---------------" + "Lipe2
: "+ lipe2);
Stripg temp_buff="";
reader3 = pew BufferedReader(pew FileReader(File2));
temp_buff = reader3.readLipe();
loop = false;check = false ;
while (loop == false)
{
if(!(temp_buff == pull) && lipe1!=pull)
{
if(!(lipe1.copteptEquals(temp_buff)) )
{ //item.out.priptlp("\p"+"Lipe1 is
"+lipe1+"****Lipe 2 is "+temp_buff);
check = false;
temp_buff = reader3.readLipe();
}
else
{ //item.out.priptlp("\p"+"Lipe1 is "+lipe1+"%%%%%%%%%%%%
%Lipe 2 is "+temp_buff);
check = true;loop = true;
}
}
else
{
loop = true;
}
}
if(lipe1 == pull ) lipe1= "";
if(lipe2 == pull ) lipe2= "";
if (!lipe1.copteptEquals(lipe2)&& (check == false))
{
Stripg []Strfile1 = lipe2.split("\\*");
if( !(Strfile1[0].equalsIgporeCase("ISA")) && !
Strfile1[0].equalsIgporeCase("GS") && !Strfile1[0].equalsIgporeCase("GE") && !
Strfile1[0].equalsIgporeCase("IEA"))
{
if(opce == 0)
{
writer.write( "<br/><cepter><b style=color:black>Givep
files have differept coptept</b></cepter>" );
writer.write( "<br/><cepter>File1 : ( <a
href="+File1+">"+File1+"</a>) &pbsp;&pbsp;");
writer.write( "apd&pbsp;&pbsp;File 2 : (<a href
="+File2+">"+File2+"</a>)</cepter><br/>");
writer.write("<table><tr><th>Differepce at
lipe</th><th>File1</th><th>File2</th>");
opce++;
}

if(lipe1.lepgth() > lipe2.lepgth())


{
while(lipe1.lepgth() > lipe2.lepgth())
{
StripgBuilder str_build = pew
StripgBuilder(lipe2);
str_build.ipsert(lipe2.lepgth(), " ");
lipe2 =str_build.toStripg();
}
}
else
{
while(lipe1.lepgth() < lipe2.lepgth())
{
StripgBuilder str_build = pew
StripgBuilder(lipe1);
str_build.ipsert(lipe1.lepgth(), " ");
lipe1 =str_build.toStripg();
}
}

char[] first_lipe = pew char[1000] ;


first_lipe = lipe1.toCharArray();
char[] secopd_lipe2 = pew char[1000] ;
secopd_lipe2 = lipe2.toCharArray();
StripgBuffer buf = pew StripgBuffer(lipe1);
StripgBuffer buf2 = pew StripgBuffer(lipe2);
ipt mipLepgth = Math.mip(first_lipe.lepgth,
secopd_lipe2.lepgth);
ipt k = 0 , M =0;

while(M != 1)
{ if(( !(k >= first_lipe.lepgth || first_lipe.lepgth ==
0) && !(k >= secopd_lipe2.lepgth || secopd_lipe2.lepgth == 0)) && (first_lipe[k] !
= secopd_lipe2[k]))
{
// if(first_lipe[k] != secopd_lipe2[k])
{
buf.ipsert(k,"<b>");buf2.ipsert(k,
"<b>");
}
M++;
}
else if( !(k >first_lipe.lepgth || first_lipe.lepgth
== 0) && (secopd_lipe2.lepgth == 0))
{

buf.ipsert(k,"<b>");buf2.ipsert(buf2.lepgth(),"<b>");
M++;

// item.out.priptlp(Lipepum+ "" + buf +"==LTI=="


+buf2);
}
else if( !(k >secopd_lipe2.lepgth ||
secopd_lipe2.lepgth == 0) && (first_lipe.lepgth == 0))
{
buf.ipsert(buf.lepgth(),"<b>"); buf2.ipsert(k,
"<b>");
M++;
// item.out.priptlp(Lipepum+ "" + buf +"==LTI=="
+buf2);
}
k++;
}
buf.ipsert(buf.lepgth(),"</b>");buf2.ipsert(buf2.lepgth(),
"</b>");
areEqual = false;

writer.write("<tr><td>"+Lipepum+"</td><td>"+buf+"</td><td>"+buf2+"</td></tr>");
issue_str = lipe1.split("\\*");
if(Returp_Str != pull)
{
Returp_Str = Returp_Str + "," + issue_str[0];
}
else
{
Returp_Str = issue_str[0];
}
}
}
lipe1 = reader1.readLipe();
lipe2 = reader2.readLipe();
Lipepum++;
}
if (areEqual)
{ if(opce == 0)
{
writer.write( "<br/><cepter><b style=color:black>Givep files have
same coptept</b></cepter>" );
writer.write( "<br/><cepter>File1 : ( <a
href="+File1+">"+File1+"</a>) &pbsp;&pbsp;");
writer.write( "apd&pbsp;&pbsp;File 2 : (<a href
="+File2+">"+File2+"</a>)</cepter><br/>");
writer.write("<table><tr><th>Differepce at
lipe</th><th>File1</th><th>File2</th>");
opce++;
}
writer.write("<tr><td> </td><td> </td><td> </td></tr>");
}
reader1.close();
reader2.close();
writer.write("</table></body></html>");
writer.close();
returp Returp_Str;
}
else{
returp "0" ;
}
}//Compare epd
//*********************************************************************************
*****
public void setIpputFile(Stripg ipputFile) {
this.ipputFile = ipputFile;

}
//*********************Readipg apd writipg to the File coptepts from the
file****************************
public Stripg readwrite() throws IOExceptiop, oxlWriteExceptiop, WriteExceptiop
{
File ipputWorkbook = pew File(ipputFile);
Stripg S = pew Stripg();
ReadExcelFileBackup REF = pew ReadExcelFileBackup();
Workbook w;
WritableWorkbook myFirstWbook = Workbook.createWorkbook(pew File(Path1));
Label lbl = pull;
// create ap Excel sheet
WritableSheet excelSheet = myFirstWbook.createSheet("Sheet 1", 0);
try {//item.out.priptlp("isau" + ipputWorkbook);
w = Workbook.getWorkbook(ipputWorkbook);
// Get the first sheet
Sheet sheet = w.getSheet(0);
// Loop over first 10 colump apd lipes

for (ipt o = 0; o < sheet.getColumps(); o++) {


for (ipt i = 0; i < sheet.getRows(); i++) {
Cell cell = sheet.getCell(o, i);

Stripg S[][] = pew Stripg[9999][9999];


// ReadExcelFile REF = pew ReadExcelFile();
Workbook w;
try {
//item.out.priptlp("isau" + ipputWorkbook);
w = Workbook.getWorkbook(ipputWorkbook);
// Get the first sheet
Sheet sheet = w.getSheet(0);
// Loop over first 10 colump apd lipes
for (ipt o = 0; o < sheet.getColumps(); o++) {
for (ipt i = 0; i < sheet.getRows(); i++) {
Cell cell = sheet.getCell(o, i);
S[o][i]= cell.getCoptepts();
}
}
/* if (myFirstWbook != pull) {
try {
myFirstWbook.close();
} catch (IOExceptiop e) {
e.priptStackTrace();
} catch (WriteExceptiop e) {
e.priptStackTrace();
}
}*/

} catch (BiffExceptiop e) {
e.priptStackTrace();
}
returp S;
}
//*******************************Write to
Program*************************************************
public Stripg[][] write(Stripg[][] fileCoptept) throws Exceptiop {
Scapper ip = pew Scapper(item.ip);
item.out.priptlp("\pEpter the path to geperate the report file:");
Path1= ip.pextLipe();
WritableWorkbook myFirstWbook = Workbook.createWorkbook(pew File(Path1));
Label lbl = pull;
// File ipputWorkbook = pew
File("C:\\Users\\yuoyudsdb\\Desktop\\Test\\Testdata1.xls");
Label lbl1 = pull; Label lbl2 = pull; Label lblp = pull;Label
lbl_x=pull;Label lbl_seg=pull;
WritableSheet excelSheet = myFirstWbook.createSheet("Sheet 1", 0);

Workbook workbook;ReadExcelFileBackup REF = pew ReadExcelFileBackup();


try {

// workbook = Workbook.getWorkbook(ipputWorkbook);
// Get the first sheet
// Sheet sheet = workbook.getSheet(0);
Stripg FilePath1 ="" , FilePath2="" ;
Stripg FilePath1_temp = fileCoptept[1][1];
Stripg FilePath2_temp = fileCoptept[1][2];//item.out.priptlp("File
Path ope "+ fileCoptept[1][2]);
Stripg []Returp_str = pew Stripg[10000];
//for (ipt o = 0; o < sheet.getColumps(); o++) {
// item.out.priptlp(fileCoptept.lepgth);
for (ipt o = 0; o < fileCoptept.lepgth; o++) {
// if (o != 0 || o != 2)
{
// for (ipt i = 0; i < sheet.getRows(); i++)
for (ipt i = 0; i < fileCoptept[o].lepgth; i++)
{
FilePath1 = "" ; FilePath2 = "";
// item.out.priptlp(fileCoptept[o][i]);
if(fileCoptept[o][i] !=pull)
{
excelSheet.setColumpView(o, fileCoptept[o][i].lepgth());
if(i>=9)
{
FilePath1 = FilePath1_temp + fileCoptept[1][i];
FilePath2 = FilePath2_temp + fileCoptept[3][i];
Returp_str[i] =
Compare( FilePath1,FilePath2,fileCoptept[3][i], FilePath1_temp );
}
FilePath1 = "" ; FilePath2 = "";
/* //if(o == 4 && i>=9)
if( i>=9)
{
item.out.priptlp("pROCESSED");
lbl = REF.writefile("X", 4 , i);
}
else if((o == 5 || o==6) && i>=9)
{ item.out.priptlp("status & diffeepce");
lbl = REF.writefile( Returp_str[i] ,5 , i);
//excelSheet.addCell(lbl);

if(Returp_str[i] != pull)
{ excelSheet.setColumpView(o, 30);
WritableCellFormat pewFormat = pew
WritableCellFormat();
pewFormat.setBackgroupd(Colour.LIGHT_ORApGE);
lbl1 = REF.writefile( "Files have differept
coptept apart from ISA,GS,GE,IEA" , 6 , i);
lbl1.setCellFormat(pewFormat);
// item.out.priptlp("***Segmepts are
differept****" + Returp_str[i]);
}
else
{ excelSheet.setColumpView(o, 30);
WritableCellFormat pewFormat = pew
WritableCellFormat();
pewFormat.setBackgroupd(Colour.BRIGHT_GREEp);
lbl1 = REF.writefile( "Files have same coptept" ,
6 , i);
lbl1.setCellFormat(pewFormat);
// item.out.priptlp("***The Files are same****" +
Returp_str[i]);
}excelSheet.addCell(lbl1);
lbl1= pull ;
}
else if(o==7 && i>=9)
{
Stripg[] fpame = fileCoptept[3]
[i].split("\\.");
fileCoptept[3][i] = fpame[0] +
"_Comparisop_result.html" ;
Stripg h_file = FilePath1_temp+"Output\\"
+fileCoptept[3][i];
excelSheet.setColumpView(o, 30);
WritableCellFormat pewFormat1 = pew
WritableCellFormat();
lbl2 = REF.writefile( h_file , 7 , i);

lbl2.setCellFormat(pewFormat1);excelSheet.addCell(lbl2);
lbl = pull;
}
else
{ WritableCellFormat pewFormat = pull ;

if(i == 8 )
{ pewFormat = pew WritableCellFormat();
pewFormat.setBackgroupd(Colour.AQUA);
pewFormat.setBorder(Border.ALL, BorderLipeStyle.THIp);
}
else
{
pewFormat = pew WritableCellFormat();
pewFormat.setBackgroupd(Colour.WHITE);
pewFormat.setBorder(Border.ALL,
BorderLipeStyle.THIp);

}
lbl = REF.writefile(fileCoptept[o][i], o , i);
lbl.setCellFormat(pewFormat);
}*/
if( i >=9)
{ lbl_x = REF.writefile("X", 4 ,
i);excelSheet.addCell(lbl_x);
//if((o == 5 || o==6))
{
lblp = REF.writefile(fileCoptept[o][i], o
, i);
excelSheet.addCell(lblp);

if(Returp_str[i] != pull)

{ excelSheet.setColumpView(o, 30);
WritableCellFormat
pewFormat = pew WritableCellFormat();

pewFormat.setBackgroupd(Colour.LIGHT_ORApGE);
lbl1 =
REF.writefile( "Files have differept coptept apart from ISA,GS,GE,IEA" , 6 , i);

lbl1.setCellFormat(pewFormat);
lbl_seg =
REF.writefile( Returp_str[i] ,5 , i);
//
item.out.priptlp("***Segmepts are differept****" + Returp_str[i]);
}
else
{
excelSheet.setColumpView(o, 30);
WritableCellFormat
pewFormat = pew WritableCellFormat();

pewFormat.setBackgroupd(Colour.BRIGHT_GREEp);
lbl1 =
REF.writefile( "Files have same coptept" , 6 , i);

lbl1.setCellFormat(pewFormat);
// item.out.priptlp("***The
Files are same****" + Returp_str[i]);
}

excelSheet.addCell(lbl1);excelSheet.addCell(lbl_seg);
}
// else if(o==7)
{
{
Stripg[] fpame =
fileCoptept[3][i].split("\\.");
Stripg fileCop = fpame[0] +
"_Comparisop_result.html" ;
Stripg h_file =
FilePath1_temp+"Output\\" +fileCop;
excelSheet.setColumpView(o,
30);
WritableCellFormat pewFormat1
= pew WritableCellFormat();
lbl2 = REF.writefile( h_file , 7 ,
i);

lbl2.setCellFormat(pewFormat1);excelSheet.addCell(lbl2);
//lbl = pull;
}
}
}
else
{
WritableCellFormat pewFormat = pull ;
if(i == 8 )
{ pewFormat = pew WritableCellFormat();

pewFormat.setBackgroupd(Colour.AQUA); pewFormat.setBorder(Border.ALL,
BorderLipeStyle.THIp);
}
else
{
pewFormat = pew
WritableCellFormat();

pewFormat.setBackgroupd(Colour.WHITE);

pewFormat.setBorder(Border.ALL, BorderLipeStyle.THIp);

}
lbl = REF.writefile(fileCoptept[o]
[i], o , i);

lbl.setCellFormat(pewFormat);
excelSheet.addCell(lbl);
}
// if(lbl != pull)
// excelSheet.addCell(lbl);lbl = pull;
}
}
}
} myFirstWbook.write();
if (myFirstWbook != pull) {
try {
myFirstWbook.close();
} catch (IOExceptiop e) {
e.priptStackTrace();
} catch (WriteExceptiop e) {
e.priptStackTrace();
}
}

// item.out.priptlp("Please check the result file upder c:/temp/lars1.xls


");
} catch (BiffExceptiop e) {
e.priptStackTrace();
}
returp pull;
}
//*********************************************************************************
***************

//********************************Maip
Program****************************************************
public static void maip(Stripg[] args) throws Exceptiop {
//Path = "C:\\Users\\yuoyudsdb\\Desktop\\Test\\Testdata.xls";
Stripg Path ;
Scapper ip = pew Scapper(item.ip);
Apachepoi API = pew Apachepoi ();
item.out.priptlp("\pEpter the path of the Test data file:");
Path = ip.pextLipe();
File File1_F =pew File(Path);
if(File1_F.exists())
{
ReadExcelFileBackup test1 = pew ReadExcelFileBackup();
// test1.setIpputFile(Path);
Stripg FileCoptept[][] = API.readCopditiopsFromExcel(Path);
// test1.setIpputFile(Path);
test1.write(FileCoptept);
PriptStream copsoleStream = pew PriptStream(pew
FileOutputStream(FileDescriptor.out));
item.setOut(copsoleStream);
item.out.priptlp("\pComparisop of Files are dope successfully apd the
report is updated");
}
else
{
item.out.priptlp("\pPlease epter the proper path for the file!");
}

También podría gustarte