Ruby Bindings for POI - initial checkin
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353634 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d52b44464e
commit
09d220e340
316
src/contrib/poi-ruby/Makefile
Normal file
316
src/contrib/poi-ruby/Makefile
Normal file
@ -0,0 +1,316 @@
|
||||
#Adapted from the Makefile for PyLucene, by the OSAF
|
||||
# Makefile for building Poi4R
|
||||
#
|
||||
# Supported operating systems: Linux, Mac OS X and Windows.
|
||||
# See INSTALL file for requirements.
|
||||
#
|
||||
# Steps to build
|
||||
# 1. Edit the sections below as documented
|
||||
# 2. make all
|
||||
# 3. make install
|
||||
#
|
||||
# The install target installs the Poi4R python extension in python's
|
||||
# site-packages directory. On Mac OS X, it also installs the gcj runtime
|
||||
# libraries into $(PREFIX)/lib.
|
||||
#
|
||||
# To successfully import the Poi4R extension into Ruby, all required
|
||||
# libraries need to be found. If the locations you chose are non-standard,
|
||||
# the relevant DYLD_LIBRARY_PATH (Mac OS X), LD_LIBRARY_PATH (Linux), or
|
||||
# PATH (Windows) need to be set accordingly.
|
||||
#
|
||||
|
||||
#
|
||||
#
|
||||
|
||||
VERSION=0.1.0
|
||||
POI_VER=2.0-final-20040126
|
||||
RUBY_VER=1.8
|
||||
|
||||
POI4R:=$(shell pwd)
|
||||
POI=$(POI4R)/poi-$(POI_VER)
|
||||
#DEBUG=1
|
||||
|
||||
#
|
||||
# You need to uncomment and edit the variables below in the section
|
||||
# corresponding to your operating system.
|
||||
#
|
||||
# PREFIX: where programs are normally installed on your system (Unix).
|
||||
# PREFIX_RUBY: where your version of python is installed.
|
||||
# GCJ_HOME: where GCC/GCJ is installed.
|
||||
# Windows drive-absolute paths need to be expressed cygwin style.
|
||||
#
|
||||
|
||||
# Mac OS X (Darwin)
|
||||
#PREFIX=/usr/local
|
||||
#PREFIX_RUBY=/Library/Frameworks/Ruby.framework/Versions/$(RUBY_VER)
|
||||
#SWIG=$(PREFIX)/bin/swig
|
||||
#GCJ_HOME=/usr/local/gcc-3.4.1
|
||||
#DB=$(POI4R)/db-$(DB_VER)
|
||||
#PREFIX_DB=/usr/local/BerkeleyDB.$(DB_LIB_VER)
|
||||
|
||||
# Linux
|
||||
PREFIX=/usr
|
||||
PREFIX_RUBY=$(PREFIX)
|
||||
SWIG=$(PREFIX)/bin/swig
|
||||
GCJ_HOME=/usr
|
||||
#DB=$(POI4R)/db-$(DB_VER)
|
||||
#PREFIX_DB=$(PREFIX)/BerkeleyDB.$(DB_LIB_VER)
|
||||
|
||||
# Windows
|
||||
#PREFIX_RUBY=/cygdrive/o/Python-2.3.2
|
||||
#SWIG=/cygdrive/c/utils/bin/swig.exe
|
||||
#GCJ_HOME=/cygdrive/o/mingw-3.1
|
||||
#DB=/cygdrive/o/db-$(DB_VER)
|
||||
#PREFIX_DB=$(DB)
|
||||
|
||||
#
|
||||
# No edits required below
|
||||
#
|
||||
|
||||
OS=$(shell uname)
|
||||
ifeq ($(findstring CYGWIN,$(OS)),CYGWIN)
|
||||
OS=Cygwin
|
||||
endif
|
||||
ifeq ($(findstring WINNT,$(OS)),WINNT)
|
||||
OS=Cygwin
|
||||
endif
|
||||
|
||||
ifeq ($(DEBUG),1)
|
||||
COMP_OPT=DEBUG=1
|
||||
SUFFIX=d
|
||||
_SUFFIX=_d
|
||||
BINDIR=debug
|
||||
else
|
||||
COMP_OPT=
|
||||
SUFFIX=
|
||||
_SUFFIX=
|
||||
BINDIR=release
|
||||
endif
|
||||
|
||||
SWIG_OPT=-DSWIG_COBJECT_TYPES -DPOI4R_VER="'$(VERSION)'" -DPOI_VER="'$(POI_VER)'"
|
||||
|
||||
JCCFLAGS=--encoding=UTF-8
|
||||
#JCCFLAGS=--encoding=UTF-8 -findirect-dispatch
|
||||
|
||||
ifeq ($(OS),Darwin)
|
||||
RUBY_SITE=$(PREFIX_RUBY)/lib/ruby$(RUBY_VER)/site-packages
|
||||
RUBY_INC=$(PREFIX_RUBY)/lib/ruby$(RUBY_VER)
|
||||
POI4R=$(BINDIR)/poi4r.so
|
||||
ifeq ($(DEBUG),1)
|
||||
CCFLAGS=-O0 -g
|
||||
LDFLAGS=-g
|
||||
else
|
||||
CCFLAGS=-O2
|
||||
LDFLAGS=
|
||||
endif
|
||||
else
|
||||
|
||||
ifeq ($(OS),Linux)
|
||||
RUBY_SITE=$(PREFIX_RUBY)/lib/ruby/site-ruby/$(RUBY_VER)/
|
||||
RUBY_INC=$(PREFIX_RUBY)/lib/ruby/$(RUBY_VER)/i686-linux
|
||||
POI4R_LIB=$(BINDIR)/poi4r.so
|
||||
ifeq ($(DEBUG),1)
|
||||
CCFLAGS=-O0 -g -fPIC
|
||||
LDFLAGS=-g
|
||||
else
|
||||
CCFLAGS=-O2 -fPIC
|
||||
LDFLAGS=
|
||||
endif
|
||||
else
|
||||
|
||||
ifeq ($(OS),Cygwin)
|
||||
RUBY_SITE=`cygpath -aw $(PREFIX_RUBY)/Lib/site-packages`
|
||||
RUBY_INC=`cygpath -aw $(PREFIX_RUBY)/Include`
|
||||
RUBY_PC=`cygpath -aw $(PREFIX_RUBY)/PC`
|
||||
POI4R_LIB=$(BINDIR)/poi4r$(_SUFFIX).so
|
||||
ifeq ($(DEBUG),1)
|
||||
CCFLAGS=-O -g
|
||||
LDFLAGS=-g
|
||||
else
|
||||
CCFLAGS=-O2
|
||||
LDFLAGS=
|
||||
endif
|
||||
else
|
||||
|
||||
RUBY=unknown
|
||||
RUBY_SITE=unknown
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
CLASSES=$(BINDIR)/classes
|
||||
JAR_CLASSES=$(CLASSES)/jar
|
||||
|
||||
CC=$(GCJ_HOME)/bin/gcc
|
||||
CXX=$(GCJ_HOME)/bin/g++
|
||||
JCC=$(GCJ_HOME)/bin/gcj
|
||||
JCCH=$(GCJ_HOME)/bin/gcjh
|
||||
JAR=$(GCJ_HOME)/bin/jar
|
||||
POI_ZIP=poi-$(POI_VER).jar
|
||||
POI_JAR=poi-$(POI_VER).jar
|
||||
|
||||
POI4R_CP:=$(BINDIR)/$(POI_JAR):$(CLASSES)
|
||||
|
||||
OBJS=$(BINDIR)/poi.o $(BINDIR)/io.java.o $(BINDIR)/io.cpp.o
|
||||
|
||||
LIBS=$(POI4R_LIB)
|
||||
|
||||
default: all
|
||||
|
||||
patches:
|
||||
|
||||
|
||||
env:
|
||||
ifndef PREFIX_RUBY
|
||||
@echo Operating system is $(OS)
|
||||
@echo You need to edit that section of the Makefile
|
||||
@false
|
||||
else
|
||||
@true
|
||||
endif
|
||||
|
||||
|
||||
$(BINDIR):
|
||||
mkdir -p $(BINDIR)/classes/jar
|
||||
|
||||
|
||||
DISTRIB=Poi-$(VERSION)
|
||||
|
||||
ifeq ($(OS),Cygwin)
|
||||
POI4R_CP:=`cygpath -awp $(POI4R_CP)`
|
||||
endif
|
||||
|
||||
|
||||
ifeq ($(OS),Cygwin)
|
||||
_poi=`cygpath -aw $(POI)`
|
||||
else
|
||||
_poi=$(POI)
|
||||
endif
|
||||
|
||||
$(BINDIR)/$(POI_JAR):
|
||||
cp $(POI4R)/$(POI_JAR) $(BINDIR)/$(POI_JAR)
|
||||
cd $(JAR_CLASSES); $(JAR) -xf $(POI4R)/$(POI_JAR)
|
||||
|
||||
$(BINDIR)/io.java.o: java/org/apache/poi/RubyOutputStream.java
|
||||
$(JCC) $(JCCFLAGS) -C -d $(CLASSES) java/org/apache/poi/RubyOutputStream.java
|
||||
$(JCC) $(JCCFLAGS) $(CCFLAGS) -I$(GCJ_HOME)/include -c -o $@ java/org/apache/poi/RubyOutputStream.java
|
||||
|
||||
$(CLASSES)/org/apache/poi/RubyOutputStream.h: $(BINDIR)/io.java.o Makefile
|
||||
mkdir -p $(CLASSES)/org/apache/poi/hssf/usermodel
|
||||
$(JCCH) -d $(CLASSES) --classpath=$(JAR_CLASSES) org.apache.poi.hssf.usermodel.HSSFWorkbook
|
||||
$(JCCH) -d $(CLASSES) --classpath=$(JAR_CLASSES) org.apache.poi.hssf.usermodel.HSSFSheet
|
||||
$(JCCH) -d $(CLASSES) --classpath=$(JAR_CLASSES) org.apache.poi.hssf.usermodel.HSSFRow
|
||||
$(JCCH) -d $(CLASSES) --classpath=$(JAR_CLASSES) org.apache.poi.hssf.usermodel.HSSFCell
|
||||
$(JCCH) -d $(CLASSES) --classpath=$(JAR_CLASSES) org.apache.poi.hssf.usermodel.HSSFHeader
|
||||
$(JCCH) -d $(CLASSES) --classpath=$(JAR_CLASSES) org.apache.poi.hssf.usermodel.HSSFFooter
|
||||
$(JCCH) -d $(CLASSES) --classpath=$(JAR_CLASSES) org.apache.poi.hssf.usermodel.HSSFFont
|
||||
$(JCCH) -d $(CLASSES) --classpath=$(JAR_CLASSES) org.apache.poi.hssf.usermodel.HSSFDataFormat
|
||||
$(JCCH) -d $(CLASSES) --classpath=$(JAR_CLASSES) org.apache.poi.hssf.usermodel.HSSFCellStyle
|
||||
$(JCCH) -d $(CLASSES) --classpath=$(CLASSES) org.apache.poi.RubyOutputStream
|
||||
|
||||
|
||||
$(BINDIR)/io.cpp.o: $(CLASSES)/org/apache/poi/RubyOutputStream.h cpp/RubyIO.cpp $(BINDIR)/io.java.o
|
||||
$(JCC) -I$(RUBY_INC) -I$(GCJ_HOME)/include -I$(CLASSES) $(CCFLAGS) -c -o $@ cpp/RubyIO.cpp
|
||||
|
||||
$(BINDIR)/poi.o: $(BINDIR)/$(POI_JAR)
|
||||
$(JCC) $(JCCFLAGS) $(CCFLAGS) -c -o $@ $(BINDIR)/$(POI_JAR)
|
||||
|
||||
Poi4R_wrap.cxx: $(BINDIR)/io.cpp.o Poi4R.i
|
||||
ifdef SWIG
|
||||
$(SWIG) $(SWIG_OPT) -I$(CLASSES) -c++ -ruby Poi4R.i
|
||||
endif
|
||||
|
||||
|
||||
ifeq ($(OS),Darwin)
|
||||
$(POI4R_LIB): $(OBJS) Poi4R_wrap.cxx
|
||||
$(CXX) -shared -bundle -o $@ $(CCFLAGS) $(SWIG_OPT) $(DB_INC) -I$(GCJ_HOME)/include -I$(CLASSES) -I$(RUBY_INC) Poi4R_wrap.cxx $(OBJS) -L$(GCJ_HOME)/lib -lgcj -liconv -undefined suppress -flat_namespace -multiply_defined suppress
|
||||
else
|
||||
|
||||
ifeq ($(OS),Linux)
|
||||
$(POI4R_LIB): $(OBJS) Poi4R_wrap.cxx
|
||||
$(CXX) -shared -o $@ $(CCFLAGS) $(SWIG_OPT) $(DB_INC) -I$(CLASSES) -I$(RUBY_INC) Poi4R_wrap.cxx $(OBJS) -lgcj
|
||||
else
|
||||
|
||||
ifeq ($(OS),Cygwin)
|
||||
$(POI4R_LIB): $(OBJS) Poi4R_wrap.cxx
|
||||
$(CXX) -c $(CCFLAGS) $(PYDBG) -D_NO_OLDNAMES -D_off_t=off_t $(SWIG_OPT) $(DB_INC) -I$(CLASSES) -I$(RUBY_PC) -I$(RUBY_INC) -o $(BINDIR)/Poi4R_wrap.o Poi4R_wrap.cxx
|
||||
$(CXX) -shared $(LDFLAGS) -o $@ $(OBJS) `cygpath -aw $(PREFIX_RUBY)/python23$(_SUFFIX).dll` $(BINDIR)/Poi4R_wrap.o -lgcj -lwin32k -lws2_32
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
all: env $(BINDIR) $(LIBS)
|
||||
@echo build of $(POI4R_LIB) complete
|
||||
|
||||
install:: all
|
||||
install Poi4R.rb $(RUBY_SITE)
|
||||
install $(POI4R_LIB) $(RUBY_SITE)
|
||||
|
||||
ifeq ($(OS),Darwin)
|
||||
install::
|
||||
install $(GCJ_HOME)/lib/libgcj.5.dylib $(PREFIX)/lib
|
||||
install $(GCJ_HOME)/lib/libstdc++.6.dylib $(PREFIX)/lib
|
||||
install $(GCJ_HOME)/lib/libgcc_s.1.0.dylib $(PREFIX)/lib
|
||||
else
|
||||
|
||||
ifeq ($(OS),Linux)
|
||||
install::
|
||||
|
||||
else
|
||||
|
||||
ifeq ($(OS),Cygwin)
|
||||
install::
|
||||
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf $(BINDIR) Poi4R.rb* Poi4R_wrap.cxx
|
||||
|
||||
realclean: clean
|
||||
rm -rf $(POI) $(STORE) $(DISTRIB)
|
||||
|
||||
distrib::
|
||||
mkdir -p $(DISTRIB)/python
|
||||
install Poi4R.rb $(DISTRIB)/python
|
||||
install $(POI4R_LIB) $(DISTRIB)/python
|
||||
install README $(DISTRIB)
|
||||
|
||||
ifeq ($(OS),Darwin)
|
||||
distrib::
|
||||
ifdef DB
|
||||
mkdir -p $(DISTRIB)/db
|
||||
install $(LIBDB_JAVA_LIB) $(DISTRIB)/db
|
||||
install libdb_java-$(DB_LIB_VER).la.osx $(DISTRIB)/db
|
||||
endif
|
||||
mkdir -p $(DISTRIB)/gcj
|
||||
install $(GCJ_HOME)/lib/libgcj.5.dylib $(DISTRIB)/gcj
|
||||
install $(GCJ_HOME)/lib/libstdc++.6.dylib $(DISTRIB)/gcj
|
||||
install $(GCJ_HOME)/lib/libgcc_s.1.0.dylib $(DISTRIB)/gcj
|
||||
else
|
||||
|
||||
ifeq ($(OS),Linux)
|
||||
distrib::
|
||||
ifdef DB
|
||||
mkdir -p $(DISTRIB)/db
|
||||
install $(LIBDB_JAVA_LIB) $(DISTRIB)/db
|
||||
endif
|
||||
mkdir -p $(DISTRIB)/gcj
|
||||
install $(GCJ_HOME)/lib/libgcj.so.5 $(DISTRIB)/gcj
|
||||
install $(GCJ_HOME)/lib/libstdc++.so.6 $(DISTRIB)/gcj
|
||||
install $(GCJ_HOME)/lib/libgcc_s.so.1 $(DISTRIB)/gcj
|
||||
else
|
||||
|
||||
ifeq ($(OS),Cygwin)
|
||||
distrib::
|
||||
ifdef DB
|
||||
mkdir -p $(DISTRIB)/db
|
||||
install $(LIBDB_JAVA_LIB) $(DISTRIB)/db
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
613
src/contrib/poi-ruby/Poi4R.i
Normal file
613
src/contrib/poi-ruby/Poi4R.i
Normal file
@ -0,0 +1,613 @@
|
||||
/* ====================================================================
|
||||
Copyright 2005 Apache Software Foundation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
%module poi4r
|
||||
|
||||
|
||||
%{
|
||||
|
||||
#include <gcj/cni.h>
|
||||
#include <java/lang/Object.h>
|
||||
#include <java/lang/Thread.h>
|
||||
#include <java/lang/ThreadGroup.h>
|
||||
#include <java/lang/Runnable.h>
|
||||
#include <java/lang/String.h>
|
||||
#include <java/lang/Throwable.h>
|
||||
#include <java/lang/Comparable.h>
|
||||
#include <java/lang/Integer.h>
|
||||
#include <java/lang/Long.h>
|
||||
#include <java/lang/Float.h>
|
||||
#include <java/lang/Double.h>
|
||||
#include <java/io/StringWriter.h>
|
||||
#include <java/io/PrintWriter.h>
|
||||
#include <java/util/Hashtable.h>
|
||||
#include <java/util/Date.h>
|
||||
#include <java/util/Calendar.h>
|
||||
#include <java/lang/System.h>
|
||||
|
||||
#include "org/apache/poi/hssf/usermodel/HSSFWorkbook.h"
|
||||
#include "org/apache/poi/hssf/usermodel/HSSFSheet.h"
|
||||
#include "org/apache/poi/hssf/usermodel/HSSFRow.h"
|
||||
#include "org/apache/poi/hssf/usermodel/HSSFCell.h"
|
||||
#include "org/apache/poi/hssf/usermodel/HSSFFont.h"
|
||||
#include "org/apache/poi/hssf/usermodel/HSSFCellStyle.h"
|
||||
#include "org/apache/poi/hssf/usermodel/HSSFDataFormat.h"
|
||||
#include "org/apache/poi/hssf/usermodel/HSSFHeader.h"
|
||||
#include "org/apache/poi/hssf/usermodel/HSSFFooter.h"
|
||||
#include "org/apache/poi/RubyOutputStream.h"
|
||||
|
||||
|
||||
typedef ::org::apache::poi::hssf::usermodel::HSSFWorkbook *jhworkbook;
|
||||
typedef ::org::apache::poi::hssf::usermodel::HSSFSheet *jhsheet;
|
||||
typedef ::org::apache::poi::hssf::usermodel::HSSFRow *jhrow;
|
||||
typedef ::org::apache::poi::hssf::usermodel::HSSFCell *jhcell;
|
||||
typedef ::org::apache::poi::hssf::usermodel::HSSFCellStyle *jhcellstyle;
|
||||
typedef ::org::apache::poi::hssf::usermodel::HSSFFont *jhfont;
|
||||
typedef ::org::apache::poi::hssf::usermodel::HSSFFooter *jhfooter;
|
||||
typedef ::org::apache::poi::hssf::usermodel::HSSFHeader *jhheader;
|
||||
typedef ::org::apache::poi::hssf::usermodel::HSSFDataFormat *jhdataformat;
|
||||
|
||||
typedef ::java::util::Date *jdate;
|
||||
typedef ::java::util::Calendar *jcalendar;
|
||||
typedef ::java::io::OutputStream *joutputstream;
|
||||
typedef ::java::io::InputStream *jinputstream;
|
||||
typedef ::java::util::Collection *jstringCollection;
|
||||
typedef ::java::util::Collection *jtermCollection;
|
||||
typedef ::java::util::Locale *jlocale;
|
||||
typedef ::java::lang::Comparable *jcomparable;
|
||||
typedef JArray<jobject> *jobjectArray;
|
||||
typedef JArray<jstring> *jstringArray;
|
||||
|
||||
|
||||
static java::lang::Thread *nextThread;
|
||||
static java::util::Hashtable *objects;
|
||||
|
||||
|
||||
static void store_reference(jobject object) {
|
||||
java::lang::Integer *ji =new java::lang::Integer(java::lang::System::identityHashCode(object));
|
||||
jobject jo = objects->get(ji);
|
||||
if (!jo) {
|
||||
// printf("put object in hash\n");
|
||||
objects->put(ji,object);
|
||||
}
|
||||
}
|
||||
static VALUE jo2rv(jobject object, swig_type_info *descriptor)
|
||||
{
|
||||
if (object == NULL)
|
||||
{
|
||||
return Qnil;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SWIG_NewPointerObj((void *) object, descriptor, 0);
|
||||
}
|
||||
}
|
||||
static int cvtptr(VALUE value, void **jo, swig_type_info *info)
|
||||
{
|
||||
if (SWIG_ConvertPtr(value, jo, info, 0) == 0)
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int rv2jo(VALUE rv, jobject *jo, swig_type_info *descriptor)
|
||||
{
|
||||
if (NIL_P(rv))
|
||||
*jo = NULL;
|
||||
else
|
||||
{
|
||||
java::lang::Object *javaObj;
|
||||
|
||||
if (cvtptr(rv, (void **) &javaObj, descriptor) == -1)
|
||||
return 0;
|
||||
|
||||
*jo = javaObj;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static jstring r2j(VALUE object)
|
||||
{
|
||||
if (NIL_P(object)){
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
char *ps = STR2CSTR(object);
|
||||
jstring js = JvNewStringLatin1(ps);
|
||||
|
||||
if (!js)
|
||||
{
|
||||
rb_raise(rb_eRuntimeError, "ruby str cannot be converted to java: %s",ps);
|
||||
}
|
||||
|
||||
return js;
|
||||
}
|
||||
}
|
||||
|
||||
VALUE j2r(jstring js)
|
||||
{
|
||||
if (!js)
|
||||
{
|
||||
return Qnil;
|
||||
}
|
||||
else
|
||||
{
|
||||
jint len = JvGetStringUTFLength(js);
|
||||
char buf[len + 1];
|
||||
|
||||
JvGetStringUTFRegion(js, 0, len, buf);
|
||||
buf[len] = '\0';
|
||||
|
||||
return rb_str_new2(buf);
|
||||
}
|
||||
}
|
||||
|
||||
static void free_java_obj(void* arg1) {
|
||||
jobject object =(jobject) arg1;
|
||||
java::lang::Integer *ji =new java::lang::Integer(java::lang::System::identityHashCode(object));
|
||||
jobject jo = objects->get(ji);
|
||||
if (jo) {
|
||||
// printf("removed object from hash\n");
|
||||
objects->remove(ji);
|
||||
}
|
||||
}
|
||||
|
||||
static void raise_ruby_error(java::lang::Throwable *e) {
|
||||
java::io::StringWriter *buffer = new java::io::StringWriter();
|
||||
java::io::PrintWriter *writer = new java::io::PrintWriter(buffer);
|
||||
e->printStackTrace(writer);
|
||||
writer->close();
|
||||
jstring message = buffer->toString();
|
||||
jint len = JvGetStringUTFLength(message);
|
||||
char buf[len + 1];
|
||||
JvGetStringUTFRegion(message, 0, len, buf);
|
||||
buf[len] = '\0';
|
||||
rb_raise(rb_eRuntimeError, "error calling poi \n %s", buf);
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
typedef long jint;
|
||||
typedef long long jlong;
|
||||
typedef char jbyte;
|
||||
typedef float jfloat;
|
||||
typedef float jdouble;
|
||||
typedef int jshort;
|
||||
typedef bool jboolean;
|
||||
|
||||
%typemap(in) SWIGTYPE * {
|
||||
|
||||
if (!rv2jo($input, (jobject *) &$1, $1_descriptor))
|
||||
rb_raise(rb_eRuntimeError, "Unrecoverable error in SWIG typemapping");
|
||||
}
|
||||
%typemap(out) SWIGTYPE * {
|
||||
|
||||
$result = jo2rv($1, $1_descriptor);
|
||||
}
|
||||
|
||||
%typemap(in) org::apache::poi::hssf::usermodel::HSSFWorkbook{
|
||||
|
||||
if (!rv2jo($input, (jobject *) &$1,
|
||||
$descriptor(org::apache::poi::hssf::usermodel::HSSFWorkbook *)))
|
||||
SWIG_fail;
|
||||
}
|
||||
%typemap(out) org::apache::poi::hssf::usermodel::HSSFWorkbook {
|
||||
$result = jo2rv($1, $descriptor(org::apache::poi::hssf::usermodel::HSSFWorkbook *));
|
||||
}
|
||||
|
||||
%typemap(in) jhsheet{
|
||||
|
||||
if (!rv2jo($input, (jobject *) &$1,
|
||||
$descriptor(org::apache::poi::hssf::usermodel::HSSFSheet *)))
|
||||
SWIG_fail;
|
||||
}
|
||||
%typemap(out) jhsheet {
|
||||
|
||||
$result = jo2rv($1, $descriptor(org::apache::poi::hssf::usermodel::HSSFSheet *));
|
||||
}
|
||||
%typemap(in) jhrow{
|
||||
|
||||
if (!rv2jo($input, (jobject *) &$1,
|
||||
$descriptor(org::apache::poi::hssf::usermodel::HSSFRow *)))
|
||||
SWIG_fail;
|
||||
}
|
||||
%typemap(out) jhrow {
|
||||
|
||||
$result = jo2rv($1, $descriptor(org::apache::poi::hssf::usermodel::HSSFRow *));
|
||||
}
|
||||
%typemap(in) jhcell{
|
||||
|
||||
if (!rv2jo($input, (jobject *) &$1,
|
||||
$descriptor(org::apache::poi::hssf::usermodel::HSSFCell *)))
|
||||
SWIG_fail;
|
||||
}
|
||||
%typemap(out) jhcell {
|
||||
|
||||
$result = jo2rv($1, $descriptor(org::apache::poi::hssf::usermodel::HSSFCell *));
|
||||
}
|
||||
%typemap(in) jhfont{
|
||||
|
||||
if (!rv2jo($input, (jobject *) &$1,
|
||||
$descriptor(org::apache::poi::hssf::usermodel::HSSFFont *)))
|
||||
rb_raise(rb_eRuntimeError, "Unrecoverable error in SWIG typemapping of HSSFFont");
|
||||
}
|
||||
|
||||
%typemap(out) jhfont {
|
||||
|
||||
$result = jo2rv($1, $descriptor(org::apache::poi::hssf::usermodel::HSSFFont *));
|
||||
}
|
||||
|
||||
%typemap(in) jhcellstyle{
|
||||
|
||||
if (!rv2jo($input, (jobject *) &$1,
|
||||
$descriptor(org::apache::poi::hssf::usermodel::HSSFCellStyle *)))
|
||||
rb_raise(rb_eRuntimeError, "Unrecoverable error in SWIG typemapping of HSSFCellStyle");
|
||||
}
|
||||
%typemap(out) jhcellstyle {
|
||||
|
||||
$result = jo2rv($1, $descriptor(org::apache::poi::hssf::usermodel::HSSFCellStyle *));
|
||||
}
|
||||
%typemap(in) jhdataformat{
|
||||
|
||||
if (!rv2jo($input, (jobject *) &$1,
|
||||
$descriptor(org::apache::poi::hssf::usermodel::HSSFDataFormat *)))
|
||||
rb_raise(rb_eRuntimeError, "Unrecoverable error in SWIG typemapping of HSSFDataFormat");
|
||||
}
|
||||
%typemap(out) jhdataformat {
|
||||
|
||||
$result = jo2rv($1, $descriptor(org::apache::poi::hssf::usermodel::HSSFDataFormat *));
|
||||
}
|
||||
|
||||
|
||||
%typemap(in) jstring {
|
||||
$1 = r2j($input);
|
||||
}
|
||||
%typemap(out) jstring {
|
||||
$result = j2r($1);
|
||||
}
|
||||
%typecheck(SWIG_TYPECHECK_STRING) jstring {
|
||||
$1 = ( NIL_P($input) || TYPE($input)==T_STRING );
|
||||
}
|
||||
|
||||
%typemap(in) joutputstream {
|
||||
|
||||
jlong ptr;
|
||||
if (!rb_respond_to($input, rb_intern("putc"))) rb_raise(rb_eTypeError,"Expected IO");
|
||||
*(VALUE *) &ptr = (VALUE) $input;
|
||||
$1 = new org::apache::poi::RubyOutputStream(ptr);
|
||||
}
|
||||
%typemap(in) jcalendar {
|
||||
$1 = java::util::Calendar::getInstance();
|
||||
//$1->setTimeInMillis((long long) NUM2DBL(rb_funcall($input,rb_intern("to_i"),0,NULL))*1000.0);
|
||||
$1->set(FIX2INT(rb_funcall($input,rb_intern("year"),0,NULL)),
|
||||
FIX2INT(rb_funcall($input,rb_intern("mon"),0,NULL))-1,
|
||||
FIX2INT(rb_funcall($input,rb_intern("day"),0,NULL)),
|
||||
FIX2INT(rb_funcall($input,rb_intern("hour"),0,NULL)),
|
||||
FIX2INT(rb_funcall($input,rb_intern("min"),0,NULL)),
|
||||
FIX2INT(rb_funcall($input,rb_intern("sec"),0,NULL))
|
||||
);
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) jcalendar {
|
||||
$1 = rb_respond_to($input, rb_intern("asctime"));
|
||||
}
|
||||
|
||||
%typemap(out) jdate {
|
||||
jlong t = ((jdate) $1)->getTime();
|
||||
//TODO: separate seconds and microsecs
|
||||
int ts=t/1000;
|
||||
$result=rb_time_new((time_t) ts, 0 );
|
||||
}
|
||||
|
||||
|
||||
%freefunc org::apache::poi::hssf::usermodel::HSSFWorkbook "free_java_obj";
|
||||
|
||||
%exception {
|
||||
try {
|
||||
$action
|
||||
} catch (java::lang::Throwable *e) {
|
||||
raise_ruby_error(e);
|
||||
}
|
||||
}
|
||||
%exception org::apache::poi::hssf::usermodel::HSSFWorkbook::HSSFWorkbook {
|
||||
try {
|
||||
$action
|
||||
store_reference(result);
|
||||
} catch (java::lang::Throwable *e) {
|
||||
raise_ruby_error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
namespace java {
|
||||
namespace lang {
|
||||
class Object {
|
||||
jstring toString();
|
||||
};
|
||||
%nodefault;
|
||||
class System : public Object {
|
||||
public:
|
||||
static jstring getProperty(jstring);
|
||||
static jstring getProperty(jstring, jstring);
|
||||
static void load(jstring);
|
||||
static void loadLibrary(jstring);
|
||||
static void mapLibraryName(jstring);
|
||||
static void runFinalization();
|
||||
static void setProperty(jstring, jstring);
|
||||
};
|
||||
%makedefault;
|
||||
}
|
||||
namespace io {
|
||||
%nodefault;
|
||||
class InputStream : public ::java::lang::Object {
|
||||
};
|
||||
class OutputStream : public ::java::lang::Object {
|
||||
};
|
||||
|
||||
%makedefault;
|
||||
}
|
||||
namespace util {
|
||||
class Date : public ::java::lang::Object {
|
||||
public:
|
||||
Date();
|
||||
Date(jlong);
|
||||
void setTime(jlong);
|
||||
jstring toString();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace org {
|
||||
namespace apache {
|
||||
namespace poi {
|
||||
namespace hssf {
|
||||
namespace usermodel {
|
||||
%nodefault;
|
||||
class HSSFWorkbook : public ::java::lang::Object {
|
||||
public:
|
||||
HSSFWorkbook();
|
||||
jstring getSheetName(jint);
|
||||
jint getNumberOfSheets();
|
||||
void setSheetOrder(jstring,jint);
|
||||
void setSheetName(jint,jstring);
|
||||
void setSheetName(jint,jstring,jshort);
|
||||
jint getSheetIndex(jstring);
|
||||
jhsheet createSheet();
|
||||
jhsheet cloneSheet(jint);
|
||||
jhsheet createSheet(jstring);
|
||||
jhsheet getSheetAt(jint);
|
||||
jhsheet getSheet(jstring);
|
||||
void removeSheetAt(jint);
|
||||
jhcellstyle createCellStyle();
|
||||
jhfont createFont();
|
||||
jhdataformat createDataFormat();
|
||||
void write(joutputstream);
|
||||
|
||||
};
|
||||
|
||||
class HSSFSheet : public ::java::lang::Object {
|
||||
public:
|
||||
jhrow createRow(jint);
|
||||
jhrow getRow(jint);
|
||||
jhfooter getFooter();
|
||||
jhheader getHeader();
|
||||
};
|
||||
class HSSFRow : public ::java::lang::Object {
|
||||
public:
|
||||
jhcell createCell(jshort);
|
||||
jhcell getCell(jshort);
|
||||
//jboolean getProtect(); //only in 2.5
|
||||
|
||||
};
|
||||
class HSSFCell : public ::java::lang::Object {
|
||||
public:
|
||||
void setCellValue(jdouble);
|
||||
void setCellValue(jstring);
|
||||
void setCellValue(jboolean);
|
||||
void setCellValue(jcalendar);
|
||||
void setCellFormula(jstring);
|
||||
jstring getStringCellValue();
|
||||
jdouble getNumericCellValue();
|
||||
jdate getDateCellValue();
|
||||
jstring getCellFormula();
|
||||
jboolean getBooleanCellValue();
|
||||
jint getCellType();
|
||||
jshort getEncoding();
|
||||
void setAsActiveCell();
|
||||
|
||||
void setCellStyle(jhcellstyle);
|
||||
void setEncoding(jshort encoding);
|
||||
|
||||
static const jint CELL_TYPE_BLANK;
|
||||
static const jint CELL_TYPE_BOOLEAN;
|
||||
static const jint CELL_TYPE_ERROR;
|
||||
static const jint CELL_TYPE_FORMULA;
|
||||
static const jint CELL_TYPE_NUMERIC;
|
||||
static const jint CELL_TYPE_STRING;
|
||||
|
||||
static const jshort ENCODING_COMPRESSED_UNICODE;
|
||||
static const jshort ENCODING_UTF_16;
|
||||
};
|
||||
class HSSFCellStyle : public ::java::lang::Object {
|
||||
public:
|
||||
static const jshort ALIGN_CENTER;
|
||||
static const jshort ALIGN_CENTER_SELECTION;
|
||||
static const jshort ALIGN_FILL;
|
||||
static const jshort ALIGN_GENERAL;
|
||||
static const jshort ALIGN_JUSTIFY;
|
||||
static const jshort ALIGN_LEFT;
|
||||
static const jshort ALIGN_RIGHT;
|
||||
static const jshort ALT_BARS;
|
||||
static const jshort BIG_SPOTS;
|
||||
static const jshort BORDER_DASH_DOT;
|
||||
static const jshort BORDER_DASH_DOT_DOT;
|
||||
static const jshort BORDER_DASHED;
|
||||
static const jshort BORDER_DOTTED;
|
||||
static const jshort BORDER_DOUBLE;
|
||||
static const jshort BORDER_HAIR;
|
||||
static const jshort BORDER_MEDIUM;
|
||||
static const jshort BORDER_MEDIUM_DASH_DOT;
|
||||
static const jshort BORDER_MEDIUM_DASH_DOT_DOT;
|
||||
static const jshort BORDER_MEDIUM_DASHED;
|
||||
static const jshort BORDER_NONE;
|
||||
static const jshort BORDER_SLANTED_DASH_DOT;
|
||||
static const jshort BORDER_THICK;
|
||||
static const jshort BORDER_THIN;
|
||||
static const jshort BRICKS;
|
||||
static const jshort DIAMONDS;
|
||||
static const jshort FINE_DOTS;
|
||||
static const jshort NO_FILL;
|
||||
static const jshort SOLID_FOREGROUND;
|
||||
static const jshort SPARSE_DOTS;
|
||||
static const jshort SQUARES;
|
||||
static const jshort THICK_BACKWARD_DIAG;
|
||||
static const jshort THICK_FORWARD_DIAG;
|
||||
static const jshort THICK_HORZ_BANDS;
|
||||
static const jshort THICK_VERT_BANDS;
|
||||
static const jshort THIN_BACKWARD_DIAG;
|
||||
static const jshort THIN_FORWARD_DIAG;
|
||||
static const jshort THIN_HORZ_BANDS;
|
||||
static const jshort THIN_VERT_BANDS;
|
||||
static const jshort VERTICAL_BOTTOM;
|
||||
static const jshort VERTICAL_CENTER;
|
||||
static const jshort VERTICAL_JUSTIFY;
|
||||
static const jshort VERTICAL_TOP;
|
||||
|
||||
jshort getAlignment();
|
||||
jshort getBorderBottom();
|
||||
jshort getBorderLeft();
|
||||
jshort getBorderRight();
|
||||
jshort getBorderTop();
|
||||
jshort getBottomBorderColor();
|
||||
jshort getDataFormat();
|
||||
jshort getFillBackgroundColor();
|
||||
jshort getFillForegroundColor();
|
||||
jshort getFillPattern();
|
||||
jshort getFontIndex();
|
||||
jboolean getHidden();
|
||||
jshort getIndention();
|
||||
jshort getIndex();
|
||||
jshort getLeftBorderColor();
|
||||
jboolean getLocked();
|
||||
jshort getRightBorderColor();
|
||||
jshort getRotation();
|
||||
jshort getTopBorderColor();
|
||||
jshort getVerticalAlignment();
|
||||
jboolean getWrapText();
|
||||
void setAlignment(jshort) ;
|
||||
void setBorderBottom(jshort );
|
||||
void setBorderLeft(jshort );
|
||||
void setBorderRight(jshort );
|
||||
void setBorderTop(jshort );
|
||||
void setBottomBorderColor(jshort );
|
||||
void setDataFormat(jshort );
|
||||
void setFillBackgroundColor(jshort );
|
||||
void setFillForegroundColor(jshort );
|
||||
void setFillPattern(jshort );
|
||||
void setFont(jhfont );
|
||||
void setHidden(jboolean );
|
||||
void setIndention(jshort );
|
||||
void setLeftBorderColor(jshort );
|
||||
void setLocked(jboolean );
|
||||
void setRightBorderColor(jshort );
|
||||
void setRotation(jshort );
|
||||
void setTopBorderColor(jshort );
|
||||
void setVerticalAlignment(jshort );
|
||||
void setWrapText(jboolean );
|
||||
};
|
||||
class HSSFDataFormat : public ::java::lang::Object {
|
||||
public:
|
||||
static jstring getBuiltinFormat(jshort);
|
||||
static jshort getBuiltinFormat(jstring);
|
||||
jstring getFormat(jshort);
|
||||
jshort getFormat(jstring);
|
||||
static jint getNumberOfBuiltinBuiltinFormats();
|
||||
//TODO static jlist getBuiltinFormats();
|
||||
|
||||
};
|
||||
class HSSFFont : public ::java::lang::Object {
|
||||
public:
|
||||
static const jshort BOLDWEIGHT_BOLD;
|
||||
static const jshort BOLDWEIGHT_NORMAL;
|
||||
static const jshort COLOR_NORMAL;
|
||||
static const jshort COLOR_RED;
|
||||
static const jstring FONT_ARIAL;
|
||||
static const jshort SS_NONE;
|
||||
static const jshort SS_SUB;
|
||||
static const jshort SS_SUPER;
|
||||
static const jshort U_DOUBLE;
|
||||
static const jshort U_DOUBLE_ACCOUNTING;
|
||||
static const jshort U_NONE;
|
||||
static const jshort U_SINGLE;
|
||||
static const jshort U_SINGLE_ACCOUNTING;
|
||||
|
||||
jshort getBoldweight();
|
||||
jshort getColor();
|
||||
jshort getFontHeight();
|
||||
jshort getFontHeightInPoints();
|
||||
jstring getFontName();
|
||||
jshort getIndex();
|
||||
jboolean getItalic();
|
||||
jboolean getStrikeout();
|
||||
jshort getTypeOffset();
|
||||
jshort getUnderline();
|
||||
void setBoldweight(jshort );
|
||||
void setColor(jshort );
|
||||
void setFontHeight(jshort );
|
||||
void setFontHeightInPoints(jshort );
|
||||
void setFontName(jstring );
|
||||
void setItalic(jboolean );
|
||||
void setStrikeout(jboolean );
|
||||
void setTypeOffset(jshort );
|
||||
void setUnderline(jshort );
|
||||
};
|
||||
%makedefault;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
%init %{
|
||||
|
||||
JvCreateJavaVM(NULL);
|
||||
JvAttachCurrentThread(NULL, NULL);
|
||||
|
||||
nextThread = new java::lang::Thread();
|
||||
objects = new java::util::Hashtable();
|
||||
|
||||
java::util::Hashtable *props = (java::util::Hashtable *)
|
||||
java::lang::System::getProperties();
|
||||
props->put(JvNewStringUTF("inRuby"), objects);
|
||||
|
||||
JvInitClass(&org::apache::poi::hssf::usermodel::HSSFFont::class$);
|
||||
JvInitClass(&org::apache::poi::hssf::usermodel::HSSFCell::class$);
|
||||
JvInitClass(&org::apache::poi::hssf::usermodel::HSSFSheet::class$);
|
||||
JvInitClass(&org::apache::poi::hssf::usermodel::HSSFCellStyle::class$);
|
||||
|
||||
%}
|
||||
|
43
src/contrib/poi-ruby/cpp/RubyIO.cpp
Normal file
43
src/contrib/poi-ruby/cpp/RubyIO.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
/* ====================================================================
|
||||
Copyright 2005 Apache Software Foundation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
#include <gcj/cni.h>
|
||||
|
||||
#include "ruby.h"
|
||||
#include "org/apache/poi/RubyOutputStream.h"
|
||||
|
||||
|
||||
/**
|
||||
* The native functions declared in org.apache.poi.RubyoutputStream
|
||||
*
|
||||
* @author aviks
|
||||
*/
|
||||
|
||||
namespace org {
|
||||
namespace apache {
|
||||
namespace poi {
|
||||
|
||||
void RubyOutputStream::close(void)
|
||||
{
|
||||
rb_funcall3((VALUE ) rubyIO, rb_intern("close"), 0, NULL);
|
||||
}
|
||||
|
||||
void RubyOutputStream::write(jint toWrite)
|
||||
{
|
||||
rb_funcall((VALUE ) rubyIO, rb_intern("putc"),1,INT2FIX(toWrite));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/* ====================================================================
|
||||
Copyright 2005 Apache Software Foundation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
|
||||
package org.apache.poi;
|
||||
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author aviks
|
||||
* Wrap a java.io.OutputStream around a Ruby IO object
|
||||
*/
|
||||
|
||||
public class RubyOutputStream extends OutputStream {
|
||||
|
||||
//pointer to native ruby VALUE
|
||||
protected long rubyIO;
|
||||
|
||||
public RubyOutputStream (long rubyIO)
|
||||
{
|
||||
this.rubyIO = rubyIO;
|
||||
// incRef();
|
||||
}
|
||||
|
||||
protected void finalize()
|
||||
throws Throwable
|
||||
{
|
||||
// decRef();
|
||||
}
|
||||
|
||||
// protected native void incRef();
|
||||
// protected native void decRef();
|
||||
|
||||
public native void close()
|
||||
throws IOException;
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.io.OutputStream#write(int)
|
||||
*/
|
||||
public native void write(int arg0) throws IOException;
|
||||
}
|
||||
|
BIN
src/contrib/poi-ruby/poi-2.0-final-20040126.jar
Normal file
BIN
src/contrib/poi-ruby/poi-2.0-final-20040126.jar
Normal file
Binary file not shown.
83
src/contrib/poi-ruby/tests/tc_base_tests.rb
Normal file
83
src/contrib/poi-ruby/tests/tc_base_tests.rb
Normal file
@ -0,0 +1,83 @@
|
||||
require 'test/unit'
|
||||
require 'release/poi4r'
|
||||
|
||||
class TC_base_tests < Test::Unit::TestCase
|
||||
|
||||
def setup()
|
||||
end
|
||||
|
||||
def test_get_constant
|
||||
h=Poi4r::HSSFWorkbook.new
|
||||
s=h.createSheet("Sheet1")
|
||||
r=s.createRow(0)
|
||||
c=r.createCell(0)
|
||||
assert_equal(3,Poi4r::HSSFCell.CELL_TYPE_BLANK,"Constant CELL_TYPE_BLANK")
|
||||
end
|
||||
|
||||
def test_base
|
||||
system("rm test.xls")
|
||||
h=Poi4r::HSSFWorkbook.new
|
||||
|
||||
#Test Sheet Creation
|
||||
s=h.createSheet("Sheet1")
|
||||
s=h.createSheet("Sheet2")
|
||||
assert_equal(2,h.getNumberOfSheets(),"Number of sheets is 2")
|
||||
|
||||
#Test setting cell values
|
||||
s=h.getSheetAt(0)
|
||||
r=s.createRow(0)
|
||||
c=r.createCell(0)
|
||||
c.setCellValue(1.5)
|
||||
assert_equal(c.getNumericCellValue(),1.5,"Numeric Cell Value")
|
||||
c=r.createCell(1)
|
||||
c.setCellValue("Ruby")
|
||||
assert_equal(c.getStringCellValue(),"Ruby","String Cell Value")
|
||||
#Test error handling
|
||||
assert_raise (RuntimeError) {c.getNumericCellValue()}
|
||||
|
||||
#Test styles
|
||||
st = h.createCellStyle()
|
||||
c=r.createCell(2)
|
||||
st.setAlignment(Poi4r::HSSFCellStyle.ALIGN_CENTER)
|
||||
c.setCellStyle(st)
|
||||
c.setCellValue("centr'd")
|
||||
|
||||
#Date handling
|
||||
c=r.createCell(3)
|
||||
t1=Time.now
|
||||
c.setCellValue(Time.now)
|
||||
t2= c.getDateCellValue().gmtime
|
||||
assert_equal(t1.year,t2.year,"year")
|
||||
assert_equal(t1.mon,t2.mon,"month")
|
||||
assert_equal(t1.day,t2.day,"day")
|
||||
assert_equal(t1.hour,t2.hour,"hour")
|
||||
assert_equal(t1.min,t2.min,"min")
|
||||
assert_equal(t1.sec,t2.sec,"sec")
|
||||
st=h.createCellStyle();
|
||||
st.setDataFormat(Poi4r::HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"))
|
||||
c.setCellStyle(st)
|
||||
|
||||
#Fonts
|
||||
c=r.createCell(4)
|
||||
font = h.createFont();
|
||||
font.setFontHeightInPoints(24);
|
||||
font.setFontName("Courier New");
|
||||
font.setItalic(true);
|
||||
font.setStrikeout(true);
|
||||
style = h.createCellStyle();
|
||||
style.setFont(font);
|
||||
c.setCellValue("This is a test of fonts");
|
||||
c.setCellStyle(style);
|
||||
|
||||
#Formulas
|
||||
c=r.createCell(5)
|
||||
c.setCellFormula("A1*2")
|
||||
assert_equal("A1*2",c.getCellFormula,"formula")
|
||||
|
||||
#Test writing
|
||||
h.write(File.new("test.xls","w"))
|
||||
assert_nothing_raised {File.new("test.xls","r")}
|
||||
#h.write(0.1)
|
||||
end
|
||||
|
||||
end
|
15
src/contrib/poi-ruby/tests/tc_gc.rb
Normal file
15
src/contrib/poi-ruby/tests/tc_gc.rb
Normal file
@ -0,0 +1,15 @@
|
||||
require 'test/unit'
|
||||
require 'release/poi4r'
|
||||
|
||||
class TC_gc < Test::Unit::TestCase
|
||||
def test_premature_collection
|
||||
h=Poi4r::HSSFWorkbook.new
|
||||
h.createSheet("Sheet1");
|
||||
5000.times do
|
||||
hh=Poi4r::HSSFWorkbook.new
|
||||
GC.start()
|
||||
end
|
||||
assert_equal(1,h.getNumberOfSheets(),"Number of sheets")
|
||||
end
|
||||
end
|
||||
|
3
src/contrib/poi-ruby/tests/ts_all.rb
Normal file
3
src/contrib/poi-ruby/tests/ts_all.rb
Normal file
@ -0,0 +1,3 @@
|
||||
require 'test/unit'
|
||||
require 'tests/tc_base_tests'
|
||||
require 'tests/tc_gc'
|
Loading…
Reference in New Issue
Block a user