⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 poi4r.i

📁 java 读写word excel ppt
💻 I
📖 第 1 页 / 共 2 页
字号:
/* ====================================================================   Licensed to the Apache Software Foundation (ASF) under one or more   contributor license agreements.  See the NOTICE file distributed with   this work for additional information regarding copyright ownership.   The ASF licenses this file to You 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))		);	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -