A kind of method and device writing form
Technical field
The application relates to field of computer technology, particularly relates to a kind of method and device writing form.
Background technology
In prior art, writing form (referring generally to excel form) based on java can be realized by poi.
Poi is the open source projects of Apache, is a kind of java application programming interface for OFFICE document
(Application Programming Interface, API), uses this API can realize Microsoft
The various operations of OFFICE document (including excel form, word document and Power Point document).
Writing form to call poi, need to compile substantial amounts of java code, these java codes are as poi
Input, for inform poi for expectation write form some limit.Specifically, some are common
Restriction includes:
1, the java class in form to be written feature so that poi according to this feature from each java class
In find the java class in form to be written.Wherein, java apoplexy due to endogenous wind comprises java object and java object
Property value.
Such as Zhang San, Li Si, king five, etc., can be java object, and those object's property values,
Can be the most such as " height ", the value of " body weight " these attributes." height " this attribute such as Zhang San
Value " 180 ", the value " 70 " of " body weight " this attribute of Li Si, etc..
2, be default value during sky when the object's property value in java apoplexy due to endogenous wind form to be written so that
When certain object's property value in java apoplexy due to endogenous wind form to be written is empty, poi can know follow-up should be by
This default value writes form as this object's property value.
3, property value present position in the table is so that property value is write the predetermined bits in form by poi
Put, as certain property value is write secondary series.
4, the data form that table cell is used is so that poi is according to this data form, to java
The property value being unsatisfactory for this data form of apoplexy due to endogenous wind carries out form conversion, such as by the attribute of non-character string format
Value is converted to the property value of string format.
5, the displaying pattern of table cell is so that poi is according to this displaying pattern, to java apoplexy due to endogenous wind
The displaying pattern of property value change, such as such for 2010-10-1 displaying pattern is converted to
2010/10/1。
6, gauge outfit title is so that poi inputs this title in gauge outfit.
Using data base and above-mentioned restriction as the input of poi, poi is called, realizes successively with poi:
Form that acquisition is to be write, the object of the java apoplexy due to endogenous wind determined in form to be written and object's property value, profit
Object and property value thereof with determining write form.
Above-mentioned prior art has the disadvantage that to call poi, needs to expend more human resources and enters
The compiling of a large amount of java codes of row.
Summary of the invention
The embodiment of the present application provides a kind of method writing form, writes form in order to be avoided to call poi and consumes
The problem taking more human resources.
The embodiment of the present application also provides for a kind of device writing form, in order to be avoided to call poi write form and
The problem expending more human resources.
The embodiment of the present application employing following technical proposals:
A kind of method writing form, comprises determining that the java class of form to be written;According to the java determined
The object of apoplexy due to endogenous wind and object's property value determine the data of input poi;Call poi by described data write table
Lattice.
A kind of device writing form, including: java class determines unit, for determining the java of form to be written
Class;Data determination unit, for determining object and the object of java apoplexy due to endogenous wind that unit determines according to java class
Property value determine input poi data;Poi call unit, is used for calling poi data determination unit is true
Fixed described data write form.
At least one technical scheme above-mentioned that the embodiment of the present application uses can reach following beneficial effect:
Owing to can first determine the java class of form to be written, and according to the object of the java apoplexy due to endogenous wind determined and
Object's property value determines the data of input poi, thus without inputting about in form to be written to poi again
The restriction of feature of java class.Therefore compared to prior art, it is possible to reduce need to call poi
The amount of java code of compiling, it is to avoid write form and the problem that expends more human resources to call poi.
Accompanying drawing explanation
Accompanying drawing described herein is used for providing further understanding of the present application, constitutes of the application
Point, the schematic description and description of the application is used for explaining the application, is not intended that to the application not
Work as restriction.In the accompanying drawings:
The flowchart of a kind of method writing form that Fig. 1 provides for the embodiment of the present application 1;
Fig. 2 is a kind of excel generation engine in order to realize the method writing form that the embodiment of the present application provides
Structural representation;
The excel that Fig. 3 provides for using the embodiment of the present application generates engine implementation and writes the flow process of excel form
Figure;
The concrete structure schematic diagram of a kind of device writing form that Fig. 4 provides for the embodiment of the present application 2.
Detailed description of the invention
For making the purpose of the application, technical scheme and advantage clearer, specifically real below in conjunction with the application
Execute example and technical scheme is clearly and completely described by corresponding accompanying drawing.Obviously, described
Embodiment is only some embodiments of the present application rather than whole embodiments.Based on the enforcement in the application
Example, the every other enforcement that those of ordinary skill in the art are obtained under not making creative work premise
Example, broadly falls into the scope of the application protection.
Below in conjunction with accompanying drawing, describe the technical scheme that each embodiment of the application provides in detail.
Embodiment 1
Form is write and the problem that expends more human resources, the embodiment of the present application 1 for being avoided to call poi
First a kind of method writing form is provided.The flowchart of the method is as it is shown in figure 1, comprise the steps:
Step 11, determines the java class of form to be written;
In the embodiment of the present application, two ways can be used to realize determining the java class of form to be written:
First kind of way: by resolving the note that java class is arranged, determine and be annotated mark to be written
Java class, as the java class of form to be written.
Use first kind of way, need java class for form to be written in advance to explain.
Concrete note mode can be: the java class for form to be written explains a mark to be written.Follow-up
When the java class treating write form is inquired about, it is possible to using this mark to be written as inquiry key
Word, inquiry has been annotated the java class of this mark.
It should be noted that call poi for minimizing as far as possible to write the form more human resources of consuming, except right
The java class of form to be written is explained outside mark to be written, it is also possible to carries out other and explains.
Such as, it is also possible to each property value present position in the table is explained.Specifically, Ke Yiwei
The value of java apoplexy due to endogenous wind different attribute explains a table position information respectively.Wherein, this table position information is used
In representing property value location (such as form certain row) in the table after write form.Based on note
The table position information solved, follow-up can indicate poi using this table position information as one of the input of poi
Corresponding property value is write the table position represented by this table position information.
For the java code corresponding relative to compiling " property value present position in the table ", for java
The human resources that class is explained spent by table position information is less, therefore relative to prior art, uses and explains
The mode of table position information, is being equally reached the purpose to poi instruction property value place table position
While, human resources can be saved.
Additionally, the embodiment of the present application can also be for java class annotating data form conversion script mark, after
If continuous certain java class parsing form to be written has been annotated this mark, then can turn according to this data form
This mark of the change of feet, calls corresponding Data Format Transform script and this java apoplexy due to endogenous wind need to be changed the genus of data form
Property value is changed, the property value after being changed.
For the java code corresponding relative to compiling " the data form that table cell is used ",
Human resources spent by java class annotating data form conversion script mark is less, therefore relative to existing
Technology, uses the mode of annotating data form conversion script mark, is being equally reached for changing number
While carrying out, according to the property value of form, the purpose changed, human resources can be saved.
Additionally, in the embodiment of the present application, it is also possible to the java class for form to be written explains " table cell
Displaying pattern " and " when the object's property value in form to be written is default value during sky ", to reach
The java code compilation resource required for those information is indicated to poi to saving.Specifically, a kind of note
Code is as follows:
Have in the note of above-mentioned comment code: the java class of form to be written, " date " this attribute
The displaying pattern of each property value and " when the object's property value in form to be written is default value during sky ".
Another kind of comment code is as follows, and this comment code is in order to realize " property value is residing in the table
Position ", " Data Format Transform script mark ", " date " this attribute each property value displaying pattern with
And the note of " when the object's property value in form to be written is default value during sky ":
In above-mentioned code, name is for configuring the gauge outfit title of the excel form of generation;Index is in order to refer to
Show which row property value is positioned at when writing excel form;Script represents for property value is carried out data lattice
The script of formula conversion, script can use groovy grammer;DateFormat be used for representing " date " this
The displaying pattern of each property value of one attribute;NullValue is used for representing " when the object in form to be written
Property value is default value during sky ".
The second way: determine the extensible markup language of java category feature for describing form to be written
(Extensible Markup Language, xml) file;According to the java parsed from this xml document
Category feature, determines the java class possessing this java category feature, as the java class of form to be written.
The second way is applicable to the object of any form to be written, is particularly suited for some and cannot be carried out explaining
Java class.
It should be noted that in addition to the characteristics of objects of form to be written, xml document can be also used for describing it
His some information, can be as previously described java class explain " property value present position in the table ",
The displaying pattern of each property value of " Data Format Transform script mark ", " date " this attribute and " when
Object's property value in form to be written is default value during sky ", etc..
Specifically, for describing the generation of a kind of typical xml document of the java category feature of form to be written
Code is as follows:
Step 12, determines the data of input poi according to the object of the java apoplexy due to endogenous wind determined and object's property value;
In one embodiment, when the data form of property value of the java apoplexy due to endogenous wind determined is without changing
Time, directly object and the object's property value of the java apoplexy due to endogenous wind determined can be defined as inputting the data of poi.
And when the property value of the java apoplexy due to endogenous wind determined comprises the property value needing to carry out form conversion, permissible
First to needing the property value carrying out form conversion to carry out form conversion, it is such as character by its Data Format Transform
String, the most again by property value, the object of java apoplexy due to endogenous wind determined and the java apoplexy due to endogenous wind determined after conversion
The data of poi it are defined as inputting without changing the property value of data form.
In one embodiment, it is possible to use Data Format Transform script realizes the form for property value
Conversion.
In one embodiment, it is arranged on the note for java class when Data Format Transform script mark
Time middle, it may be determined that this Data Format Transform script mark in note.And then, from the java apoplexy due to endogenous wind determined
Property value in determine the property value that need to change data form after, can be according to this Data Format Transform script mark
Know, call corresponding Data Format Transform script and the property value that need to change data form is changed, obtain
Property value after conversion.Finally, the object of java apoplexy due to endogenous wind that by the property value after conversion, can determine and
The data being defined as inputting poi without changing the property value of data form of the java apoplexy due to endogenous wind determined.
Step 13, calls poi and the data of the input poi determined is write form.
In one embodiment, if having explained table position information for java class, then may determine that this table
Lattice positional information, and call poi perform: by input poi data write form in by this table position
Position represented by information.
It should be noted that the executive agent of each step of the provided method of embodiment 1 may each be same and sets
Standby, or, the method also by distinct device as executive agent.Such as, the holding of step 11 and step 12
Row main body can be equipment 1, and the executive agent of step 13 can be equipment 2;The most such as, step 11
Executive agent can be the executive agent of equipment 1, step 12 and step 13 can be equipment 2;Etc..
Use the said method that the embodiment of the present application provides, owing to can first determine the java of form to be written
Class, and the data of input poi are determined according to the object of the java apoplexy due to endogenous wind determined and object's property value, thus
Without inputting the restriction about the java category feature in form to be written to poi again.Therefore compared to existing skill
Art, it is possible to reduce need the amount of java code of compiling in order to call poi, it is to avoid in order to call poi
The problem writing form and expend more human resources.
In one embodiment, the said method that the embodiment of the present application provides can be by as shown in Figure 2
Excel generates engine implementation.Wherein, this excel generate engine include explain module, Property Handler module,
Flowing water class Command Line Parsing module, poi module and groovy module.Hereafter functional realiey respective to each module
Mode is simply introduced.
Explain module, for java class being carried out previously described various note, and for explaining
Java class is provided for describing the xml document of its feature etc..
Property Handler module, is built-in with script processor, and this script processor can call groovy
Script is changed needing the property value carrying out Data Format Transform.
The data inputting this module are written in excel form by poi module, i.e. poi for realization.
Groovy module, has been used for compiling and the operation of each groovy script in script processor, simultaneously
The groovy object producing each script caches, it is to avoid the compilation operations of repetition.Wherein, different
Groovy script can realize the property value to different data format and carry out data format conversion, thus real
Now the property value of different data format is converted into the property value of certain type (such as character string).
Flowing water class Command Line Parsing module, for resolving the various notes arranged for java class.May
The note being resolved to such as may have following one or more:
Mark to be written;
Property value present position in the table;
Data Format Transform script identifies;
The displaying pattern of table cell;
When the object's property value in form to be written is default value during sky;
Gauge outfit title.
Function based on above-mentioned module, in one embodiment, the process writing excel form can be such as figure
Shown in 3, including:
Explain the java class that module is form to be written and explain mark to be written, table position information, additionally,
The mark of corresponding groovy script is changed for needing the property value changing data form to explain.
Flowing water class Command Line Parsing module, after receiving and writing excel form instruction, is java class to explaining module
The note arranged resolves, and according to analysis result, it is thus achieved that possess the java class of mark to be written and obtain
Obtain table position information, and the mark of groovy script.For needing to change the property value of data form
For, the mark of those property values and corresponding groovy script is sent to Property Handler module.This
Outward, by the object of the java apoplexy due to endogenous wind of acquisition and the genus of the mark not being annotated groovy script of object
Property value is sent to poi module.
Property value that Property Handler module sends according to flowing water class Command Line Parsing module and corresponding groovy
The mark of script, runs script processor.Carrying out practically mode is: trigger script processor according to groovy
The mark of script, request groovy module, by running corresponding groovy script, completes property value
Data Format Transform, property value after being changed also is sent to poi module.
The object received and property value thereof (are included the attribute without carrying out Data Format Transform by poi module
Property value after value, and conversion) write in excel form, flow process terminates.
Embodiment 2
For the inventive concept identical with the embodiment of the present application 1, the embodiment of the present application 2 provides one to write form
Device, write form and the problem that expends more human resources in order to be avoided to call poi.This device
Concrete structure schematic diagram as shown in Figure 4, determines unit 41, data determination unit 42 and Poi including java class
Call unit 43.The functional realiey mode of each unit described in detail below.
Java class determines unit 41, for determining the java class of form to be written;
Data determination unit 42, for determine according to java class java apoplexy due to endogenous wind that unit 41 determines object and
Object's property value determines the data of input poi;
Poi call unit 43, for calling the data write form that data determination unit 42 is determined by poi.
In one embodiment, java class determines that unit 41 may be used for: set java class by resolving
The note put, determines the java class being annotated mark to be written, as the java class of form to be written.
In one embodiment, java class determines that unit 41 may be used for: determine for describing to be written
The extensible markup language xml document of the java category feature of form;According to parse from xml document
Java category feature, determines the java class possessing this java category feature, as the java class of form to be written.
In one embodiment, java class determines that unit 41 can be also used for: determine that note is data base
In table position information.Thus Poi call unit 43 can be used for: call poi and perform data are determined list
Unit 42 determine data write form in by the position represented by this table position information.
In one embodiment, java class determines that unit 41 can be also used for: determines and is labeled in data base
In Data Format Transform script mark.Thus data determination unit 42 may be used for: from the attribute determined
Value determines the property value that need to change data form;Identify according to Data Format Transform script, call corresponding
The property value that need to change data form is changed by Data Format Transform script, the attribute after being changed
Value;By the object of the java apoplexy due to endogenous wind determined, conversion after property value and determine without changing data form
Property value be defined as input poi data.
Use the said apparatus that the embodiment of the present application provides, owing to can first determine the java of form to be written
Class, and the data of input poi are determined according to the object of the java apoplexy due to endogenous wind determined and object's property value, thus
Without inputting the restriction of the feature about the java class in form to be written again to poi.Therefore compared to existing
Technology, it is possible to reduce need the amount of java code of compiling in order to call poi, it is to avoid in order to call poi
The problem writing form and expend more human resources.
Those skilled in the art are it should be appreciated that embodiments of the invention can be provided as method, system or meter
Calculation machine program product.Therefore, the present invention can use complete hardware embodiment, complete software implementation or knot
The form of the embodiment in terms of conjunction software and hardware.And, the present invention can use and wherein wrap one or more
Computer-usable storage medium containing computer usable program code (include but not limited to disk memory,
CD-ROM, optical memory etc.) form of the upper computer program implemented.
The present invention is with reference to method, equipment (system) and computer program product according to embodiments of the present invention
The flow chart of product and/or block diagram describe.It should be understood that can by computer program instructions flowchart and
/ or block diagram in each flow process and/or flow process in square frame and flow chart and/or block diagram and/
Or the combination of square frame.These computer program instructions can be provided to general purpose computer, special-purpose computer, embedding
The processor of formula datatron or other programmable data processing device is to produce a machine so that by calculating
The instruction that the processor of machine or other programmable data processing device performs produces for realizing at flow chart one
The device of the function specified in individual flow process or multiple flow process and/or one square frame of block diagram or multiple square frame.
These computer program instructions may be alternatively stored in and computer or the process of other programmable datas can be guided to set
In the standby computer-readable memory worked in a specific way so that be stored in this computer-readable memory
Instruction produce and include the manufacture of command device, this command device realizes in one flow process or multiple of flow chart
The function specified in flow process and/or one square frame of block diagram or multiple square frame.
These computer program instructions also can be loaded in computer or other programmable data processing device, makes
Sequence of operations step must be performed to produce computer implemented place on computer or other programmable devices
Reason, thus the instruction performed on computer or other programmable devices provides for realizing flow chart one
The step of the function specified in flow process or multiple flow process and/or one square frame of block diagram or multiple square frame.
In a typical configuration, calculating equipment includes one or more processor (CPU), input/defeated
Outgoing interface, network interface and internal memory.
Internal memory potentially includes the volatile memory in computer-readable medium, random access memory
(RAM) and/or the form such as Nonvolatile memory, such as read only memory (ROM) or flash memory (flash RAM).
Internal memory is the example of computer-readable medium.
Computer-readable medium includes that removable media permanent and non-permanent, removable and non-can be by appointing
Where method or technology realize information storage.Information can be computer-readable instruction, data structure, program
Module or other data.The example of the storage medium of computer includes, but are not limited to phase transition internal memory
(PRAM), static RAM (SRAM), dynamic random access memory (DRAM), its
The random access memory (RAM) of his type, read only memory (ROM), electrically erasable are read-only
Memorizer (EEPROM), fast flash memory bank or other memory techniques, read-only optical disc read only memory
(CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tape, tape magnetic
Disk storage or other magnetic storage apparatus or any other non-transmission medium, can be used for storage can be calculated
The information that equipment accesses.According to defining herein, computer-readable medium does not include temporary computer-readable matchmaker
Body (transitory media), such as data signal and the carrier wave of modulation.
Also, it should be noted term " includes ", " comprising " or its any other variant are intended to non-
Comprising of exclusiveness, so that include that the process of a series of key element, method, commodity or equipment not only wrap
Include those key elements, but also include other key elements being not expressly set out, or also include for this process,
The key element that method, commodity or equipment are intrinsic.In the case of there is no more restriction, statement " include
One ... " key element that limits, it is not excluded that including the process of described key element, method, commodity or setting
Other identical element is there is also in Bei.
It will be understood by those skilled in the art that embodiments herein can be provided as method, system or computer journey
Sequence product.Therefore, the application can use complete hardware embodiment, complete software implementation or combine software and
The form of the embodiment of hardware aspect.And, the application can use and wherein include calculating one or more
The computer-usable storage medium of machine usable program code (include but not limited to disk memory, CD-ROM,
Optical memory etc.) form of the upper computer program implemented.
The foregoing is only embodiments herein, be not limited to the application.For this area skill
For art personnel, the application can have various modifications and variations.All institutes within spirit herein and principle
Any modification, equivalent substitution and improvement etc. made, within the scope of should be included in claims hereof.