I am trying to work the code, with the attached files, only between

//READING//////////////////////////////////////////////////////////////

//WRITING//////////////////////////////////////////////////////////////

So that I may create a word.doc file template, purely from java code.

So that when my destination file, output.doc. is opened with Word97 up,

I have an initial, blank document.

Within the READING and WRITING sections of my code, where is my error?

May this also be done with the header of an excel.cls 97 upwards POI file?

----------------------------------------------------------------------------------------------------------------

import java.io.*;

import java.nio.*;

import java.util.concurrent.*;

import org.apache.poi.*;

import org.apache.poi.hwpf.*; 

import org.apache.poi.hwpf.usermodel.*;

import org.apache.poi.hwpf.model.io.*; 

import org.apache.poi.poifs.filesystem.*;

import org.apache.poi.poifs.storage.*; 

public class POIWordTest { //when writing, needs exclusive access to a file.

//can use endless BigInteger increment trick

//to generate unique files.

//or a file unique to user criteria. 


public static void main (String [] args)


{


/*

1 8

108 -1


*/


try {


//READING//////////////////////////////////////////////////////////////

FileInputStream input = new FileInputStream(new File("one.doc"));

HeaderBlockReader reader = new HeaderBlockReader(input);

IntBuffer header = IntBuffer.allocate((reader.getBATArray()).length);

header.put(reader.getBATArray());



for (int i = 0;i<header.array().length;i++)

{

System.out.println(header.get(i));

}

System.out.println();

System.out.println("length "+header.array().length);

input.close();

//////////////////////////////////////////////////////////////////////




//WRITING//////////////////////////////////////////////////////////////

class MyHeaderBlockWriter extends HeaderBlockWriter

{

MyHeaderBlockWriter()

{super();}


void write(java.io.OutputStream stream, byte[] data) throws IOException

{


doWriteData(stream,data);


}


} 


FileOutputStream fileOutput = new FileOutputStream (new File ("output.doc"));

ByteBuffer bytes = ByteBuffer.allocate(109);

bytes.put((new Integer(0)).byteValue());



for(int i=1;i<bytes.array().length;i++)

{

bytes.put((new Integer(-1)).byteValue()); 

} 

MyHeaderBlockWriter writer = new MyHeaderBlockWriter(); 

writer.write(fileOutput,bytes.array());

fileOutput.close();

////////////////////////////////////////////////////////////////////////////












/*

FileOutputStream newWordFile = new FileOutputStream(new File("POIWord.doc"));

newWordFile.close();

FileInputStream input = new FileInputStream(new File("POIWord.doc"));

POIFSFileSystem fileSystem = HWPFDocument.verifyAndBuildPOIFS(input);

input.close();

HWPFDocument document = new HWPFDocument(fileSystem); 


// document.write(new FileOutputStream(new File("POIWord.doc")));

*/


//document header problem.






//FontTable fontTable = document.getFontTable();

//List fontList = Arrays.asList(fontTable.getFontNames()); 

//This is how to wrap a primitive array.

//ListIterator fonts = fontList.iterator();


//while(fonts.hasNext())

//{System.out.println(next.toString());}


//Range range = document.getOverallRange();

//CharacterRun runOne = range.getCharacterRun(0);

//Range rageOne = new Range(0,3000,document);

//CharacterRun runTwo = runOne.insertAfter("This is some initial Text");

//runTwo.setBold(true);

//runTwo.setColor(colorOne);

//runTwo.setFontSize(16);

//runTwo.setFtcFE(ftcfe);

//Create a paragraph:

//Paragraph paragraphOne = new Paragraph(0,200,document.getRange());

//document.write(new FileOutputStream(new File("WordFile1.doc")));

}


catch (Exception e)

{e.printStackTrace();}

}

}

Reply via email to