2006年11月17日

<script language"savascript">
  if(self!=top){ // 被嵌在框架里的情况
    top.location=self.location;
   }
  if(opener){ // 被window.opne()函数弹出的情况
    opener.location.replace(self.location);
    self.close();
   }
  if(window.dialogArguments){ // 被window.showModalDialog()等弹出模态窗口的情况
    window.dialogArguments.location.replace(self.location);
    self.close();
   }
</script>

以上代码放在<head></head>标签内

2006年11月16日

<script language="javascript">
function screenInfo(){
    var  s = "";
   s += "\r\n网页可见区域宽:"+ document.body.clientWidth;
   s += "\r\n网页可见区域高:"+ document.body.clientHeight;
   s += "\r\n网页可见区域宽:"+ document.body.offsetWidth  +" (包括边线的宽)";
   s += "\r\n网页可见区域高:"+ document.body.offsetHeight +" (包括边线的宽)";
   s += "\r\n网页正文全文宽:"+ document.body.scrollWidth;
   s += "\r\n网页正文全文高:"+ document.body.scrollHeight;
   s += "\r\n网页被卷去的高:"+ document.body.scrollTop;
   s += "\r\n网页被卷去的左:"+ document.body.scrollLeft;
   s += "\r\n网页正文部分上:"+ window.screenTop;
   s += "\r\n网页正文部分左:"+ window.screenLeft;
   s += "\r\n屏幕分辨率的高:"+ window.screen.height;
   s += "\r\n屏幕分辨率的宽:"+ window.screen.width;
   s += "\r\n屏幕可用工作区高度:"+ window.screen.availHeight;
   s += "\r\n屏幕可用工作区宽度:"+ window.screen.availWidth;
   alert(s);
}
</script>


单击 演示 查看效果

 

函数名  解释  举例
 Element.toggle  交替隐藏或显示  Element.toggle(”div1”)
 Element.hide  隐藏  Element.hide(”div1”,”div2”)
 Element.show 显示  Element.show(”div1”,”div2”)
 Element.remove  删除  Element.remove(”div1”,”div2”)
 Element.getHeight  取得高度  Element.getHeight(”div1”)
 Toggle.display  和Element.toggle相同  Toggle.display(”div1”,”div2”)
 Insertion.Before  在DIV前插入文字  Insertion.Before(”div1”,”my content”)
 Insertion.After  在DIV后插入文字  Insertion.After(”div1”,”my content”)
 Insertion.Top  在DIV里最前插入文字  Insertion.Top(”div1”,”this is a text”)
 Insertion.Bottom  在DIV里最后插入文字  Insertion.Bottom(”div1”,”this is a text”)
 PeriodicalExecuter  以给定频率调用一段JavaScript  PeridicalExecutor(test, 1)"这里test是Javascript的函数,1是频率(1秒).
 $  取得一个DIV, 相当于getElementById()  $(”div1”)
 Field.clear  清空一个输入框  Field.clear(”textfield1”)
 Field.focus 把 焦点集中在输入框上  Field.focus(‘’select1”)
 Field.present  判断内容是否为空  alert(Field.present(”textfield1”))"
 Field.select  选择输入框的内容  Field.select(”textfield1”)"
 Field.activate  把 焦点集中在输入框上并选择输入框的内容  Field.activate(”textfield1”)"
 Form.serialize  把表格内容转化成string  
 Form.getElements  取得表格内容为数组形式  
 Form.disable  disable表格所有内容  Form.disable(”form1”) (这个好象不work)
 Form.focusFirstElement  把焦点集中在表格第一个元素上  Form.focusFirstElement(”form1”)
 Form.reset  Reset表格 Form.reset(”form1”)
 Form.Element.getValue  取得表格输入框的值  Form.Element.getValue(”text1”)
 Form.Element.serialize   把表格中输入框内容转化成string  Form.Element.serialize(”text1”)
 $F  等同于Form.Element.getValue()  $F(”text1”)
 Effect.Highlight  高亮特效.  Effect.Highlight(”text1”)
 Effect.Fade  褪色特效  
 Effect.Scale  放大缩小(百分比)

Effect.Scale(”text1”, 200)
这里200 = 200%, 即两倍

 Effect.Squish  消失特效.文字缩小后消失  Effect.Squish(”text1”)
 Effect.Puff  消失特效.文字放大后消失  Effect.Puff(”text1”)
 Effect.Appear  出现特效  
 Effect.ContentZoom  ZOOM特效.  
 Ajax.Request  传送Ajax请求给服务器  Ajax.Request(”http://server/s.php”)
 Ajax.Updater  传送Ajax请求给服务器并用答复的结果更新指定的Container  Ajax.Updater(”text1”,”http://server/s.php”)

      基本用法:prototype.js给每个主要的类都分了一个Class,使用起来很方便.要产生特定的效果,只要用new Class.function(<argument>)就可以了.例如:

<DIV id="div1"><a href="#" onclick="new Element.toggle('div2')">Click Me</a></DIV>
<DIV id="div2">Hello!</DIV>

      当点击Click Me的时候,div2就会交替隐藏或显示.注意,你可以给toggle加上无限个parameter,比如Element.toggle(”div2”,”div3”,”div4”,…)

2006年11月15日

关于netstat命令,我们先来看看windows帮助文件中的介绍:

Netstat
显示协议统计和当前的 TCP/IP 网络连接。该命令只有在安装了 TCP/IP 协议后才可以使用。

netstat

参数

-a:显示所有连接和侦听端口。服务器连接通常不显示。

-e:显示以太网统计。该参数可以与 -s 选项结合使用。

-n:以数字格式显示地址和端口号(而不是尝试查找名称)。

-s:显示每个协议的统计。默认情况下,显示 TCP、UDP、ICMP 和 IP 的统计。-p 选项可以用来指定默认的子集。

-p protocol:显示由 protocol 指定的协议的连接;protocol 可以是 tcp 或 udp。如果与 -s 选项一同使用显示每个协议的统计,protocol 可以是 tcp、udp、icmp 或 ip。

-r:显示路由表的内容。

interval:重新显示所选的统计,在每次显示之间暂停 interval 秒。按 CTRL+B 停止重新显示统计。如果省略该参数,netstat 将打印一次当前的配置信息。

 

好了,看完这些帮助文件,我们应该明白netstat命令的使用方法了。现在就让我们现学现用,用这个命令看一下自己的机器开放的端口。进入到命令行下,使用netstat命令的a和n两个参数:
C:\>netstat -an

Active Connections

Proto Local Address   Foreign Address   State
TCP   0.0.0.0:80          0.0.0.0:0                   LISTENING
TCP   0.0.0.0:21          0.0.0.0:0                   LISTENING
TCP   0.0.0.0:7626     0.0.0.0:0                   LISTENING
UDP   0.0.0.0:445      0.0.0.0:0
UDP   0.0.0.0:1046    0.0.0.0:0
UDP   0.0.0.0:1047    0.0.0.0:0

netstat命令查看本机开放端口:

用netstat -a —n命令查看端口!netstat后有一些英文,我来简单说一下这些英文具体都代表什么

LISTEN:侦听来自远方的TCP端口的连接请求

SYN-SENT:再发送连接请求后等待匹配的连接请求

SYN-RECEIVED:再收到和发送一个连接请求后等待对方对连接请求的确认

ESTABLISHED:代表一个打开的连接

FIN-WAIT-1:等待远程TCP连接中断请求,或先前的连接中断请求的确认

FIN-WAIT-2:从远程TCP等待连接中断请求

CLOSE-WAIT:等待从本地用户发来的连接中断请求

CLOSING:等待远程TCP对连接中断的确认

LAST-ACK:等待原来的发向远程TCP的连接中断请求的确认

TIME-WAIT:等待足够的时间以确保远程TCP接收到连接中断请求的确认

CLOSED:没有任何连接状态

2006年11月14日




Java Excel 2.6.2 API 指南

目录

简介
读电子表格
写电子表格
      基本原理
      添加格式信息
      格式化数值型数据
      格式化日期型数据
复制或修改电子数据表格
演示 & 测试程序
常问问题解答
      java.lang.OutOfMemory 异常
      编译
      上传电子数据表格
      对图表、宏和图片的支持
      日期显示
      Cell formats across multiple workbooks
      跨工作表公式

简介

本篇简介意在展示如何通过JExcel读和写Excel数据。本指南不是完全手册,并且有些没有介绍的功能,并不代表JExcel没有。本篇读物旨在鼓励和研究API文档和例子代码(特别是Write.java 和 ReadWrite.java),并更深刻地了解JExcel的功能和局限。

读电子数据表格

JExcelApi能够从存储在本地文件系统的文件或某些数入流中读取Excel数据表格。首先第一步是从一个文件或输入流读取数据表格到一个Workbook,下面的代码展示了从本地文件系统的文件创建Workbook。


import java.io.File;
import java.util.Date;
import jxl.*;

Workbook workbook = Workbook.getWorkbook(new File("myfile.xls"));

(注意:在创建Workbook对象前,从ServletInputStream创建电子表格时,必须先去除HTTP头信息。)

一旦你能访问workbook,你就能使用他访问各自的工作表(sheet)。这些工作表以索引0开始编号,一次为0,1,2等。(你也可以通过工作表名称访问工作表。)

Sheet sheet = workbook.getSheet(0);

一旦你有了sheet,你就可以访问每个单元格(cell)。你可以方便地通过方法 getContents() 将单元格的内容作为字符串访问。下面的代码,a1是文本型单元格,b2是数值型单元格,c3是日期型单元格。这些单元格的内容可以象下面这样访问。

Cell a1 = sheet.getCell(0,0);
Cell b2 = sheet.getCell(1,1);
Cell c2 = sheet.getCell(2,1);

String stringa1 = a1.getContents();
String stringb2 = b2.getContents();
String stringc2 = c2.getContents();

// Do stuff with the strings etc

演示程序 CSV.java and XML.java使用方法getContents()输出了电子表格的数据。

然而如果需要通过精确的数据类型访问单元格的内容,比如:数值型或日期类型,就需要调用相对应的方法获得正确数据类型的数据。 下面的代码片断展示了使用JExcel API从Excel表格获取double和java.util.Date类型的数据。

String stringa1 = null;
double numberb2 = 0;
Date datec2 = null;

Cell a1 = sheet.getCell(0,0);
Cell b2 = sheet.getCell(1,1);
Cell c2 = sheet.getCell(2,1);

if (a1.getType() == CellType.LABEL)
{
  LabelCell lc = (LabelCell) a1;
  stringa1 = lc.getString();
}

if (b2.getType() == CellType.NUMBER)
{
  NumberCell nc = (NumberCell) b2;
  numberb2 = nc.getValue();
}

if (c2.getType() == CellType.DATE)
{
  DateCell dc = (DateCell) c2;
  datec2 = dc.getDate();
}

// Do stuff with dates and doubles

当访问完所有的单元格后,需要使用 close() 方法。该方法将释放读取电子表格和导入的包所使用的内存。

// Finished – close the workbook and free up memory
workbook.close();

 

写电子表格

基本原理

本节描述怎样输出简单的没有任何格式的电子表格。和读一个电子表个类似,首先第一步需要通过Workbook类的工厂方法创建一个可写的workbook。


import java.io.File;
import java.util.Date;
import jxl.*;
import jxl.write.*;

WritableWorkbook workbook = Workbook.createWorkbook(new File("output.xls"));

This creates the workbook object. The generated file will be located in the current working directory and will be called "output.xls". The API can also be used to send the workbook directly to an output stream eg. from a web server to the user’s browser. If the HTTP header is set correctly, then this will launch Excel and display the generated spreadsheet.

The next stage is to create sheets for the workbook. Again, this is a factory method, which takes the name of the sheet and the position it will occupy in the workbook. The code fragment below creates a sheet called "First Sheet" at the first position.

WritableSheet sheet = workbook.createSheet("First Sheet", 0); //在指定索引0处创建名为First Sheet的工作表

Now all that remains is to add the cells into the worksheet. This is simply a matter of instantiating cell objects and adding them to the sheet. The following code fragment puts a label in cell A3, and the number 3.14159 in cell D5.

Label label = new Label(0, 2, "A label record"); // 在列0行2上创建label单元格
sheet.addCell(label); // 添加单元格

Number number = new Number(3, 4, 3.1459);
sheet.addCell(number);

There are a couple of points to note here. Firstly, the cell’s location in the sheet is specified as part of the constructor information. Once created, it is not possible to change a cell’s location, although the cell’s contents may be altered.

The other point to note is that the cell’s location is specified as (column, row). Both are zero indexed integer values – A1 being represented by (0,0), B1 by (1,0), A2 by (0,1) and so on.

Once you have finished adding sheets and cells to the workbook, you call write() on the workbook, and then close the file. This final step generates the output file (output.xls in this case) which may be read by Excel. If you call close() without calling write() first, a completely empty file will be generated.


// All sheets and cells added. Now write out the workbook
workbook.write();
workbook.close();

 

添加格式信息

The previous section illustrates the fundamentals of generating an Excel compatible spreadsheet using the JExcelApi. However, as it stands Excel will render the data in the default font, and will display the numbers to 3 decimal places. In order to supply formatting information to Excel, we must make use of the overloaded constructor, which takes an additional object containing the cell’s formatting information (both the font and the style).

The code fragment below illustrates creating a label cell for an arial 10 point font.


// Create a cell format for Arial 10 point font
WritableFont arial10font = new WritableFont(WritableFont.ARIAL, 10);
WritableCellFormat arial10format = new WritableCellFormat (arial10font);

// Create the label, specifying content and format
Label label2 = new Label(1,0, "Arial 10 point label", arial10format);
sheet.addCell(label2);

Cell formats objects are shared, so many cells may use the same format object, eg.

Label label3 = new Label(2, 0, "Another Arial 10 point label", arial10format);
sheet.addCell(label3);

This creates another label, with the same format, in cell C1.

Because cell formats are shared, it is not possible to change the contents of a cell format object. (If this were permitted, then changing the contents of the object could have unforeseen repurcussions on the look of the rest of the workbook). In order to change the way a particular cell is displayed, the API does allow you to assign a new format to an individual cell.

The constructors for the WritableFont object have many overloads. By way of example, the code fragment below creates a label in 16 point Times, bold italic and assigns it to position D1.

// Create a cell format for Times 16, bold and italic
WritableFont times16font = new WritableFont(WritableFont.TIMES, 16, WritableFont.BOLD, true);
WritableCellFormat times16format = new WritableCellFormat (times16font);

// Create the label, specifying content and format
Label label4 = new Label(3,0, "Times 16 bold italic label", times16format);
sheet.addCell(label4);

 

格式格数值型数据

Number formatting information may be passed to the cell format object by a similar mechanism to that described for fonts.

A variety of predefined number formats are defined statically. These may be used to format numerical values as follows:


WritableCellFormat integerFormat = new WritableCellFormat (NumberFormats.INTEGER);
Number number2 = new Number(0, 4, 3.141519, integerFormat);
sheet.addCell(number2);

WritableCellFormat floatFormat = new WritableCellFormat (NumberFormats.FLOAT);
Number number3 = new Number(1, 4, 3.141519, floatFormat);
sheet.addCell(number3);

The above code inserts the value 3.14159 into cells A5 and B5, using the preset integer and floating points format respectively. When Excel renders these cells, A5 will display as "3" and B5 will display as "3.14", even though both cells contain the same floating point value.

It’s possible for a user to define their own number formats, by passing in a number format string. The string passed in should be in the same format as that used by the java.text.DecimalFormat class. To format a number to display up to five decimal places in cell C5, the following code fragment may be used:

NumberFormat fivedps = new NumberFormat("#.#####");
WritableCellFormat fivedpsFormat = new WritableCellFormat(fivedps);
Number number4 = new Number(2, 4, 3.141519, fivedpsFormat);
sheet.addCell(number4);

It is, of course, also possible to specify font information as well eg. to display the same value in the 16 point times bold font defined earlier we can write

WritableCellFormat fivedpsFontFormat = new WritableCellFormat (times16font, fivedps);
Number number5 = new Number(3, 4, 3.141519, fivedpsFontFormat);
sheet.addCell(number5);

 

格式化日期型数据

Dates are handled similarly to numbers, taking in a format compatible with that used by the java.text.SimpleDateFormat class. In addition, several predefined date formats are specified in the jxl.write.DateFormat class.

As a brief example, the below code fragment illustrates placing the current date and time in cell A7 using a custom format:


// Get the current date and time from the Calendar object
Date now = Calendar.getInstance().getTime();
DateFormat customDateFormat = new DateFormat ("dd MMM yyyy hh:mm:ss");
WritableCellFormat dateFormat = new WritableCellFormat (customDateFormat);
DateTime dateCell = new DateTime(0, 6, now, dateFormat);
sheet.addCell(dateCell);

As with numbers, font information may be used to display the date text by using the overloaded constructors on WritableCellFormat.

For a more extensive example of writing spreadsheets, the demonstration program Write.java should be studied. In addition to the functionality described above, this program tests out a variety of cell, formatting and font options, as well as displaying cells with different background and foreground colours, shading and boundaries.

 

复制和修改电子表格

This section describes the scenario where a spreadsheet is read in, it’s contents altered in some way and the modified spreadsheet written out.

The first stage is to read in the spreadsheet in the normal way:


import java.io.File;
import java.util.Date;
import jxl.*;
import jxl.write.*;

Workbook workbook = Workbook.getWorkbook(new File("myfile.xls"));

This creates a readable spreadsheet. To obtain a writable version of this spreadsheet, a copy must be made, as follows:

WritableWorkbook copy = Workbook.createWorkbook(new File("output.xls"), workbook);

The API functions this way is for reasons of read efficiency (since this is the primary use of the API). In order to improve performance, data which relates to output information (eg. all the formatting information such as fonts) is not interpreted when the spreadsheet is read, since this is superfluous when interrogating the raw data values. However, if we need to modify this spreadsheet a handle to the various write interfaces is needed, which can be obtained using the copy method above. This copies the information that has already been read in as well as performing the additional processing to interpret the fields that are necessary to for writing spreadsheets. The disadvantage of this read-optimized strategy is that we have two spreadsheets held in memory rather than just one, thus doubling the memory requirements. For this reason copying and modifying large spreadsheets can be expensive in terms of processing and memory.

Once we have a writable interface to the workbook, we may retrieve and modify cells. The following code fragment illustrates how to modify the contents of a label cell located in cell B3 in sheet 2 of the workbook.

WritableSheet sheet2 = copy.getSheet(1);
WritableCell cell = sheet2.getWritableCell(1, 2);

if (cell.getType() == CellType.LABEL)
{
  Label l = (Label) cell;
  l.setString("modified cell");
}

There is no need to call the add() method on the sheet, since the cell is already present on the sheet. The contents of numerical and date cells may be modified in a similar way, by using the setValue() and setDate() methods respectively.

Although cell formats are immutable, the contents of a cell may be displayed differently by assigning a different format object to the cell. The following code fragment illustrates changing the format of numerical cell (in position C5) so that the contents will be displayed to five decimal places.

WritableSheet sheet2 = copy.getSheet(1);
WritableCell cell = sheet2.getWritableCell(2, 4);

NumberFormat fivedps = new NumberFormat("#.#####");
WritableCellFormat cellFormat = new WritableCellFormat(fivedps);
cell.setFormat(cellFormat);

Since the copy of the workbook is an ordinary writable workbook, new cells may be added to the sheet, thus:

Label label = new Label(0, 2, "New label record");
sheet2.addCell(label);

Number number = new Number(3, 4, 3.1459);
sheet2.addCell(number);

As before, once the modifications are complete, the workbook must be written out and closed.


// All cells modified/added. Now write out the workbook
copy.write();
copy.close();

The demo program contained in the source file ReadWrite.java may be studied as a more exhaustive example of how spreadsheets may be modified. This demo program copies the spreadsheet passed in on the command line; if the spreadsheet to be copied is the example spreadsheet, jxlrwtest.xls, located in the current directory, then certain modifications are carried out. DO NOT MODIFY THE EXAMPLE SPREADSHEET, otherwise the demo program will not work.

 

演示和程序测试

JExcelApi comes with a raft of demonstration and test programs contained in the package jxl.demo. These may be accessed from the command line as follows


java -jar jxl.jar -csv spreadsheet.xls

Reads spreadsheet.xls and writes out the corresponding csv data to the standard output. The -csv option is the default and may omitted

java -jar jxl.jar -xml spreadsheet.xls

Reads spreadsheet.xls and writes out the corresponding cell data to the standard output as XML.

java -jar jxl.jar -xml -format spreadsheet.xls

As above, but includes formatting information (font, number formats etc) in the generated XML

java -jar jxl.jar -formulas spreadsheet.xls

Reads spreadsheet.xls and displays all the formulas contained in that sheet.

java -jar jxl.jar -write test.xls

Generates a sample test spreadsheet called test.xls

java -jar jxl.jar -rw in.xls out.xls

Reads in.xls, copies it and generates a file called out.xls. If the spreadsheet passed in is a special sample spreadsheet called jxlrwtest.xls, then this demo will modify specific cells in the copy, out.xls.

 

常问问题解答

java.lang.OutOfMemory 异常

By default a JVM places an upper limit on the amount of memory available to the current process in order to prevent runaway processes gobbling system resources and making the machine grind to a halt. When reading or writing large spreadsheets, the JVM may require more memory than has been allocated to the JVM by default – this normally manifests itself as a java.lang.OutOfMemory exception.

For command line processes, you can allocate more memory to the JVM using the -Xms and -Xmx options eg. to allocate an initial heap allocation of 10 mB, with 100 mB as the upper bound you can use


java -Xms10m -Xmx100m -classpath jxl.jar spreadsheet.xls

In order to allocate more memory in this manner to servlets/JSPs, consult the help documentation for the Web Application Server.

 

编译

The distribution of JExcelApi comes with a build.xml file. This may be used by the build tool, ant, in order to build the software. If ant is not already installed on your machine, it may obtained

here.

To build API using ant simply change to the subdirectory called build, from the command line, type

ant

This will detect any source files which have recent changes, compile them and create the jar file in the parent directory.

The build.xml specifies a number of targets. To totally rebuild the whole application, including the javadoc documentation, then obtain a command line prompt within the build directory and type

ant jxlall

As an alternative to using ant, JExcelApi may be built using the standard java tools. From the command line in the build subdirectory issue the following sequence of commands (modifying file separators and classpath separators as required for the target operating system):

javac -d out -classpath out:../src ../src/jxl/demo/*.java
jar cmf jxl.mf ../jxl.jar -C out common jxl

 

通过浏览器上传电子表格

Below is some indicative code which may be used for uploading spreadsheets from a client browser to servlet.

In the HTML page which is displayed to the user requesting the upload, declare a form of multipart form data:


<form action="/test/upload" method="post" enctype="multipart/form-data">
  <input size="70" type="file" name="spreadsheet" />
  <br /><br /><br />
  <input type="submit" value="Upload File" />
</form>

The servlet which processes this code should access the input stream directly. Because of the encoding method, it is not possible to use the request.getParameter() methods.

Accessing the input stream directly means that the HTTP information is present. The first thing to do is strip off this redundant information before passing the input stream directly to the API, thus:

protected void doPost(HttpServletRequest request, HttpServletResponse response)
   throws IOException, ServletException
{
   try
   {
     ServletInputStream is = request.getInputStream();
     byte[] junk = new byte[1024];
     int bytesRead = 0;

     // the first four lines are request junk
     bytesRead = is.readLine(junk, 0, junk.length);
     bytesRead = is.readLine(junk, 0, junk.length);
     bytesRead = is.readLine(junk, 0, junk.length);
     bytesRead = is.readLine(junk, 0, junk.length);

     Workbook workbook = Workbook.getWorkbook(is);

     // Do stuff with the workbook
     …
   }
   catch (JXLException e)
   {
    …
   }
}

 

对图表、宏和图片的支持

JExcelApi has limited support for charts: when copying a spreadsheet containing a chart, the chart is written out to the generated spreadsheet (as long as the sheet containing the chart contains other data as well as the chart).

All macro and information is ignored. Consequently when copying and writing out the macros that were in the original will not be present in the generated version.

All image information is preserved when copying spreadsheets. When adding an image to a spreadsheet only images in PNG format are supported

日期显示

When displaying dates, the java.util package automatically adjusts for the local timezone. This can cause problems when displaying dates within an application, as the dates look as if they are exactly one day previous to that which is stored in the Excel spreadsheet, although this is not in fact the case.

Excel stores dates as a numerical value, and the conversion process for transforming this into a java.util.Date consists of converting the Excel number into a UTC value and then using the UTC number to create the java Date. Say the number in Excel represents 20 August 2003, then the UTC equivalent of this number is used to create a java.util.Date object.

The problem occurs if you are operating in a timezone other than GMT. As soon as you try and perform any user IO on that java Date object (eg. System.out.print(date)) the JVM will perform timezone adjustment calculations. If you are located in EST zone (which is GMT – 5 hours) java will subtract 5 hours from the date – so the Date object instead of being 00:00 20/08/2003 becomes 19:00 19/08/2003. Because java recognizes you only want a date and not a date time, it truncates the hours/minutes/seconds and presents 19/08/2003 – so it appears that the day is one day less than was stored in Excel, whereas it is really only a few hours (the timezone offset) less. Needless to say, this is a very annoying feature.

The easiest way to work around this (and the method used internally by the getContents() method of a jxl.DateCell) is to force the timezone of the date format as follows:


TimeZone gmtZone = TimeZone.getTimeZone("GMT");
SimpleDateFormat format = new SimpleDateFormat("dd MMM yyyy");
format.setTimeZone(gmtZone);

DateCell dateCell = ….
String dateString = format.format(dateCell.getDate());

跨电子表格的

Sometimes a single process may generate multiple workbooks. When doing this is it tempting to create the various cell formats once (eg. as member data or as static constants) and apply them to cells in both workbooks. This works fine for the first workbook, but for subsequent workbooks this can cause unexpected cell formatting. The reason for this is that when a format is first added to a workbook, JExcelApi assigns an internal cross-reference number to that cell, and all other cells which share this format simply store the cross reference number. However, when you add the same cell format to a different workbook, JExcelApi recognizes that the format has been added to a workbook, and simply refers to the format by the index number, rather than by initializing it properly. When Excel then tries to read this workbook, it sees an index number, but is unable to read the cell format (or reads a different one) as the cell can be formatted in an unpredictable manner.

The long and the short of it is that if it is necessary to re-use formats across multiple workbooks, then the WritableCellFormat objects must be re-created and initialised along with the each Workbook instance, and NOT re-used from a previous workbook.

跨工作表公式

JExcelApi supports formulas across sheets. However, please make sure all the sheets have been added to the workbook (even if they are blank) before attempting to create cross sheet formulas. This is because if you create a cross sheet formula referencing a sheet and then subsequently and or remove sheets from the workbook, the sheet reference in the formula when it was parsed won’t necessarily reference the correct sheet, and could even cause Excel to crash

Back to JExcelApi home

 

session在发生在以下情况时将失效:
  1.session的持有者(即客户端浏览器)在最大无活动等待时间(timeout)内无任何响应或请求;
  2.session被调用invalidate()方法强制使其失效;
  3.服务器重起或发生中断(此时应该是所有session都将失效);

用户关闭浏览器后标志着:
  1.session将不再发送请求到服务器;
  2.该session将不会有人调用他的invalidate()方法;
所以,此时只能等待session自己超时死亡,如果设置了该session的timeout为-1,那么这个session只有在服务器重启时才失效。

2006年06月27日

FCKeditor简介及常用配置
======================================================================
FCKeditor是一套开源的在线WYSIWYG编辑器,它几乎囊括了现在网上所有的在线编辑器的功能,特别适合于在线编辑文章和新闻等。功能强大,配置简单,支持多国语言。版本包括javascript版,Java版和.Net版。其官方网站为:http://www.fckeditor.net/,基于GNU许可协议,目前最新版本为2.3。以下主要以javascript版为例简要说明配置和使用方法。假设我的上下文路径为/cms,下载FCKeditor_2.3,将其中的FCKeditor目录解压到/cms/js目录下。

FCKeditor包含2个主要文件:fckeditor.js和fckconfig.js,通过配置文件可以方便完成自定义的使用方案。主要配置文件为fckconfig.js,位于FCKeditor根目录下面,不过建议不要更改这个文件,最好建立自己的配置文件,这样可以及时的恢复到最初始的配置。在FCKeditor目录下的editor目录下建立一个myConfig.js文件,然后打开fckconfig.js文件修改
FCKConfig.CustomConfigurationsPath的值为myConfig.js,如下:
FCKConfig.CustomConfigurationsPath = ‘myConfig.js’ ;
这样就可以在myConfig.js文件中根据需要配置各种参数;如:
// 默认语言
FCKConfig.DefaultLanguage = ‘zh-cn’;
// 是否处理HTML实体,为true时会将双引号,单引号字符转换成相应的转义符,如:&quote; &#39;
FCKConfig.ProcessHTMLEntities  = false ;
// 隐藏"插入图片"对话框中的"链接"
FCKConfig.ImageDlgHideLink    = true ;
// 隐藏"插入图片"对话框中的"高级"
FCKConfig.ImageDlgHideAdvanced  = true ;
// 隐藏"插入图片"对话框中的浏览服务器按钮
FCKConfig.ImageBrowser = false ;

下面说明几个常用的配置属性
FCKConfig.CustomConfigurationsPath
自定义配置文件的路径,根目录为FCKeditor\editor目录,也就是说自定义的配置文件只能放在FCKeditor\editor目录下,或者该目录下的某子目录,不能放在该目录以上的目录.

FCKConfig.EditorAreaCSS 编辑器界面的样式表文件

FCKConfig.BaseHref 编辑器中链接地址的默认值。
假如一个有效的图片文件的完整url为:http://223.254.101.1:8080/cms/uploads/img.jpg.
如果编辑器中需要用到相对于上下文的路径,则该参数值必须是“主机名+上下文名”,如:http://223.254.101.1:8080/cms/,这时相对路径uploads/img.jpg才是有效的;否则编辑器中的相对路径只是相对于主机名的地址,如uploads/img.gif是一个无效的相对地址

FCKConfig.FullPage 编辑器中的内容默认是否包含html页面的<html><head><body>等标签
FCKConfig.SkinPath 编辑器外观路径
FCKConfig.PluginsPath 编辑器插件路径
FCKConfig.AutoDetectLanguage 是否自动检测浏览器默认语言
FCKConfig.DefaultLanguage 默认编辑器语言
FCKConfig.StartupFocus 是否自动聚焦到编辑器内
FCKConfig.TabSpaces 是否支持Tab空格1支持0不支持
FCKConfig.ToolbarSets[key] 定义工具条
FCKConfig.ContextMenu 鼠标右健上下文菜单
FCKConfig.FontColors 编辑器工具条中文字颜色的列表项
FCKConfig.FontNames 编辑器工具条中字体的列表项
FCKConfig.FontSizes 编辑器工具条中字体大小的列表项,注意列表项目用;分隔,每个列表项/之前是字体大小值,后面是显示的名字
FCKConfig.MaxUndoLevels 可以撤销操作的步数
FCKConfig.LinkBrowser 是否允许使用"插入图片"对话框中的链接中的浏览服务器上的文件
FCKConfig.ImageBrowser 是否允许使用插入图片中浏览服务上的文件
FCKConfig.FlashBrowser 是否允许使用插入Flash中浏览服务上的文件
FCKConfig.LinkUpload 是否打开链接中的上传功能
FCKConfig.ImageUpload 是否打开插入图片中的上传功能
FCKConfig.FlashUpload 是否打开插入Flash中的上传功能

一个完整的自定义配置文件如下:
start——————————————————————
// FCKeditor自定义配置文件myConfig.js,位于FCKeditor\editor目录下

// 默认语言
FCKConfig.DefaultLanguage = ‘zh-cn’ ;

// 是否处理HTML实体,为true时会将双引号,单引号字符转换成相应的转义符,如:&quote; &#39;
FCKConfig.ProcessHTMLEntities = false ;

// 隐藏"插入图片"对话框中的"链接"
FCKConfig.ImageDlgHideLink  = true ;
// 隐藏"插入图片"对话框中的"高级"
FCKConfig.ImageDlgHideAdvanced = true ;

// 隐藏"插入图片"对话框中的浏览服务器按钮
FCKConfig.ImageBrowser = false ;

// 自定义工具栏图标,可以根据需要隐藏一些不常用的功能. ‘-’表示分隔符,用[]括起来的是一条工具栏,’/'表示换行显示
FCKConfig.ToolbarSets["Default"] = [
 ['Source','DocProps','-','Save','NewPage','Preview','-','Templates'],
 ['Cut','Copy','Paste','PasteText','PasteWord','-','Print','SpellCheck'],
 ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
//暂时隐藏表单工具条
//['Form','Checkbox','Radio','TextField','Textarea','Select','Button','ImageButton','HiddenField'],
 ’/',
 ['Bold','Italic','Underline','StrikeThrough','-','Subscript','Superscript'],
 ['OrderedList','UnorderedList','-','Outdent','Indent'],
 ['JustifyLeft','JustifyCenter','JustifyRight','JustifyFull'],
 ['Link','Unlink','Anchor'],
//暂时隐藏"Flash"功能
//['Image','Flash','Table','Rule','Smiley','SpecialChar','PageBreak','UniversalKey'],
 ['Image','Table','Rule','Smiley','SpecialChar','PageBreak','UniversalKey'],
 ’/',
 ['Style','FontFormat','FontName','FontSize'],
 ['TextColor','BGColor'],
 ['FitWindow','-','About']
] ;
end——————————————————————-

 

在网页中使用FCKeditor
=======================================================================
将FCKeditor目录解压到/cms/js目录,配置自定义配置文件后,接下来说明页面中的使用:
首先将fckeditor.js包含到网页中,如下:
<script type="text/javascript" src="js/FCKeditor/fckeditor.js"></script>
FCKeditor提供2中创建实例的方法:

方法一:在需要显示FCKeditor编辑器的地方插入以下js代码:
<script language="javascript">
  // 创建相当于<textarea name="editor" style="width:100%;"></textarea>的对象
  // 参数’editor’是产生的textarea的name值
  var oFCKeditor = new FCKeditor(‘editor’) ;
  oFCKeditor.BasePath = "$link.ContextPath/js/FCKeditor/" ; // 必须指定
  oFCKeditor.Config["BaseHref"]="$link.ContextURL/"; // 保证相对路径相对于上下文
  oFCKeditor.Config["DefaultLanguage"]="zh-cn"; // 默认语言
  oFCKeditor.Width = "100%"; // 编辑器宽度
  oFCKeditor.Height = "370"; // 编辑器高度
  oFCKeditor.Create() ;
</script>

方法二:在页面的onload事件中,添加以下代码以替换一个已经存在的TEXTAREA标记
<html>
  <head>
    <script type="text/javascript">
      window.onload = function() {
        var oFCKeditor = new FCKeditor(‘MyTextarea’) ;
        oFCKeditor.ReplaceTextarea() ;
      }
    </script>
  </head>
  <body>
    <textarea id="MyTextarea" name="MyTextarea">This is <b>the</b> initial value.</textarea>
  </body>
</html>

方法二适合于需要给编辑器赋初始值的情况。

FCKeditor功能强大,但要真正符合我们的需求还需要做必要的修改,以下将对图片上传功能做相关的修改说明:
1.打开文件FCKeditor\editor\dialog\fck_image\fck_image.js,找到以下行:
window.parent.AddTab( ‘Info’, FCKLang.DlgImgInfoTab ) ;

FCKLang.DlgImgInfoTab表示插入图片对话框中的“图像”标签,将该行转移到第二个if语句后面,这样插入图片对话框打开时默认显示的标签将不是“图像”。根据需要此行也可以不改动。

2.打开文件FCKeditor\fckconfig.js,增加一个函数contextPath:
function contextPath(str){
  var ctx = "";
  var index = str.indexOf("/");
  if(index == 0){
    var index2 = str.substring(1).indexOf("/");
    if(index2 == -1){
       index2 = str.substring(1).length;
    }
    ctx = str.substring(1,index2 + 1);
  } else {
    ctx = str.substring(0,index);
  }
  return "/" + ctx;
}
修改FCKConfig.ImageUploadURL为:
FCKConfig.ImageUploadURL = contextPath(FCKConfig.BasePath) + "/fileList.do?type=uploadImg";

3.打开文件FCKeditor\editor\dialog\fck_image.html,找到id分别为divInfo和divUpload的div行互换,目的是配合上面的修改1,实现“上传”标签在“图像”标签之后。

4.增加一个文件imgUploadComplete.vm,用于在文件上传完毕后调用插入图片对话框中的函数,将上传的图片信息传递给插入图片对话框。文件源码如下:
<html>
<head><title></title>
<script language="javascript">
  window.parent.OnUploadCompleted($!errorNumber, "$!imgSrc", "$!fileName", "$!data");
</script>
</head>
<body></body>
</html>

$!errorNumber等变量由后台程序赋值。
函数OnUploadCompleted位于FCKeditor\editor\dialog\fck_image\fck_image.js中,主要是对图片上传完之后的处理,如提示信息等,可以根据需要酌情修改。

图片上传原理
=======================================================================
在插入图片对话况中的上传页面中(即FCKeditor\editor\dialog\fck_image\fck_image.js),有一个不可见的name值为UploadWindow的iframe,上传图片时form的target就是指向此iframe,图片上传完后此iframe中的页面就跳转到页面imgUploadComplete.vm,此页面一加载就马上调用方法OnUploadCompleted将上传图片的信息返回给插入图片对话框,此信息中最主要的是图片上传后的相对于网站的相对地址。

FCKeditor字符转义的问题
=======================================================================
在没有对FCKeditor作任何配置时,FCKeditor会对以下字符作相应转义:
"转换为&quote;
‘转换为&#39;
<转换为&lt;
>转换为&gt;
&转换为&amp;
?转换为&nbsp;
其中,通过配置FCKConfig.ProcessHTMLEntities为false可以阻止"和’的转义,而?的自动转义我个人认为是一个bug。
在FCKeditor\fckeditor.js文件中增加一个函数:
function restoreHtmlEntity(htmlText){
  var text = htmlText;
  text = text.replace(/&lt;/g,’<’);
  text = text.replace(/&gt;/g,’>’);
  text = text.replace(/&amp;/g,’&’);
  return text;
}
功能是将字符串htmlText中的<,>h和&转义后的字符还原,这个函数在页面中提交数据到后台时会用到。具体用法如下:
var text = FCKeditorAPI.GetInstance(‘editor’).GetXHTML(true); // editor为编辑器的name值
document.myForm.Body.value = restoreHtmlEntity(text); // 调用函数restoreHtmlEntity还原转义字符
另外还要修改FCKeditor.prototype._HTMLEncode函数,将其中的正则表达式替换语句注释掉,目的是禁止对双引号、尖括号等字符转义。

对?的自动转义问题的解决方法:
1.找到文件FCKeditor\editor\js\fckeditorcode_ie.js,定位到第29行,找到方法名为FCKXHtmlEntities.Initialize的函数体,在函数的最后2行找到FCKXHtmlEntities.Entities={ ‘?’:'nbsp’ },将此语句改成FCKXHtmlEntities.Entities={}

2.找到文件FCKeditor\editor\js\fckeditorcode_gecko.js,定位到第28行,找到方法名为FCKXHtmlEntities.Initialize的函数体,在函数的最后2行找到FCKXHtmlEntities.Entities={ ‘?’:'nbsp’ },将此语句改成FCKXHtmlEntities.Entities={}

2005年09月09日
JSP中对复选框checkbox的取值
    使用复选框选可以很方便的一次选择多个数据,对于用户来说是很方便的。下面给出一种实现方法,共同学习。如果有其他更好的方法,也希望各位能共享出来。

页面中的处理:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>复选框的全选</title>
</head>
<body>
<script language="JavaScript" type="text/JavaScript">
/* 是否全选标记 */
var checkedAll = false;
/* 全选/取消全选
* formName 所在form的name值
* checkboxName checkbox的name值
* 注意:所有checkbox的name值都必须一样,这样才能达到全选的效果
*/
function selectAll(formName,checkboxName){
 var form = document.all.item(formName);
 var elements = form.elements[checkboxName];
 for (var i=0;i<elements.length;i++){
  var e = elements[i];
  if(checkedAll){
   e.checked = false;
   form.alls.checked = false;
  } else {
   e.checked = true;
   form.alls.checked = true;
  }
 }
 if(checkedAll){
  checkedAll = false;
 } else {
  checkedAll = true;
 }
}
/* 检查是否有checkbox被选中
* formName 所在form的name值
* checkboxName checkbox的name值
* 注意:所有checkbox的name值都必须一样,这样才能达到全选的效果
*/
function checkAll(formName,checkboxName){
 var hasCheck = false;
 var form = document.all.item(formName);
 var elements = form.elements[checkboxName];
 for (var i=0;i<elements.length;i++){
   var e = elements[i];
   if(e.checked){
     hasCheck = true;
    }
  }
  return hasCheck;
}
/* 执行操作 */
function do_action(){
  if (!checkAll("formName","no")){
    alert("没有checkbox被选中,提示用户至少选择一个!");
  } else {
    alert("已有checkbox被选中,可以继续后续操作!");
  }
}
</script>
<form name="formName" method="get">
  <table id="dataList" width="200" align="center" border="1">
    <tr>
      <td><input type="checkbox" name="alls" onClick="selectAll(‘formName’,'no’)" title="全选/取消全选">
      </td>
      <td align="center"> 学号 </td>
      <td align="center"> 姓名 </td>
    </tr>
    <tr>
      <td><input type="checkbox" name="no" value="001" title="选择/不选择">
      </td>
      <td> 001 </td>
      <td> 张三 </td>
    </tr>
    <tr>
      <td><input type="checkbox" name="no" value="002" title="选择/不选择">
      </td>
      <td> 002 </td>
      <td> 李四 </td>
    </tr>
  </table>
  <p align="center">
    <input type="button" name="actionButton" value="操作" onClick="do_action()">
  </p>
</form>
</body>
</html>

 

后台的取值方法:

String no[] = request.getParameterValues("no");

2005年03月17日

1、确认CVSNT已经安装好,并能正常运行;WinCvs刚刚安装。

2、第一次运行WinCvs会弹出一个配置参数框。
  General标签的配置如下:
 ◇Authentication:pserver 选择认证方式,一般最常用的就是pserver
 ◇Path:/cvsroot 库文件所在的目录
 ◇Host address:10.87.170.99 CVSNT服务器的IP地址或计算机名
 ◇User name:administrator 第一次配置时用windows的管理员身份登陆,以便设置其他用户权限
 ◇CVSROOT:添好上面4项后会自动生成。

3、配置好后,登录。

4、建库:将已准备好的工程(可以是空的)"import moudule"到CVSNT服务器上的库中。

5、"check out"一个库下来,因为如果不下一个库下来,不能给这个库设置拥有者及权限。

6、选中新库的根目录,按【ctr+L】弹出命令框,依次执行一下命令:
 ◇cvs chacl default:r   设置默认权限为只读。
 ◇cvs lsacl                    列出所有的用户及其相应的权限(r 读 w 写 c 创建和删除)
 ◇cvs passwd -a cvspub  添加一个用户cvspub,删除一个用户的命令为cvs passwd -x cvspub
 ◇cvs chown cvspub      设置该库的拥有者
 ◇cvs chacl cvspub:rw   设置用户cvspub的权限。要设置用户对某一个文件夹的权限, 先用鼠标在左边树型结构框中选中该文件夹,然后执行同样的命令。