import java.io.*;
import jxl.*;
import jxl.write.*;
//import TXT data into Excel with Java
Public class Createxls
{
Public static void Main (String args[])
{
Try
{
//Open File
Writableworkbook book= Workbook.createworkbook (New File ("Test. xls"));
//Generate a worksheet named "first page", parameter 0 indicates this is the first page
Writablesheet Sheet=book.createsheet ("first page", 0);
//In the construction child of the label object, the cell position is the first column, the first row (0,0)
//And cell content is test
label Label=new label (0,0, "test");
//Add a defined cell to the worksheet
Sheet.addcell (label);
/ * Generate a cell that holds numbers
the full package path of number must be used, otherwise there is a syntax ambiguity
The cell position is the second column, the first row, and the value is 789.123*/
jxl.write.Number number = new Jxl.write.Number (1,0,789.123);
Sheet.addcell (number);
//write data and close file
book.write ();
book.close ();
}catch (Exception e)
{
System.out.println (e);
}
}
}
Import Java.io.BufferedWriter;
Import Java.io.File;
Import Java.io.FileWriter;
Import java.io.IOException;
Import JXL. Cell;
Import JXL. Sheet;
Import JXL. Workbook;
Import jxl.read.biff.BiffException;
Importing Excel data into TXT with Java
public class Writetxt {
Public static void Main (string[] args) {
//TODO auto-generated method stub
String filepath = "D:\\demo.xls";
try {
Workbook Workbook = Workbook.getworkbook (new File (filepath));
Sheet Sheet = workbook.getsheet (0);
File File = new file ("D:/1.txt");
FileWriter fw = new FileWriter (file);
bufferedwriter bw = new BufferedWriter (FW);
//J is the number of rows, Getcell ("column number", "line number")
Int J = sheet.getrows ();
int y = sheet.getcolumns ();
for (int i = 0; i < J; i++) {
for (int x=0; x<y; x + +) {
Cell C = Sheet.getcell (x, i);
String s = c.getcontents ();
Bw.write (s);
bw.write ("");
Bw.flush ();
}
bw.newline ();
Bw.flush ();
}
System.out.println ("Write End");
} catch (Biffexception e) {
e.printstacktrace ();
} catch (IOException e) {
e.printstacktrace ();
}
}
}
Problems encountered: TXT file in the cell data between the use of | split, with string.split ("\\|"); Extracting data
Using Java to achieve the translation of Excel and txt files