Java Implementation Excel--excel Cell design

Source: Internet
Author: User

The bottom-level implementation of Excel is implemented using C + +, and if I use the Java language, I first need to object to the cell, that is, a cell class to represent each cell (actually a data structure);

During my programming, when designing a simple class, I often need to analyze it from its parent class, interface, Field, method and so on, in order to meet the requirements of function, performance and extensibility.

1) interface Analysis

Serializable interface, Excel cells need to implement replication function, or drag function, it must be copied ( must be deep copy ), so you need to implement the serializable interface, through the method of stream deep copy

Comparable interface, if the cell needs to be sorted, the CompareTo method must be implemented.


2) field analysis

The role of field is to summarize the 2 roles that are used to identify cells and save cell information .


int Row;int col; Equivalent to the primary key of the cell data structure, the cell can be obtained through HASHMAP.

Object value; The equivalent of a cell is cached only, saving the cell's calculated value after the formula. such as 1+1=2, the value is 2.

String function; The string that holds the formula. such as A3=A1+A2, you need to save the "A1+a2" string in A3.

Boolean calculated; with the help of the caching idea , it is guaranteed to calculate the value once at a time, such as the calculated=false of all cells before the calculation; one calculation is, a1=1/3+1; a2=a1*3; in A1=1/3+1, the A1 is computed once, the calculated=true of A1 is set, the value is saved to value, and when the a2=a1*3 is calculated, the A1 is evaluated and replaced directly with value.

Arraylist<cell> Relationcell; Save the relevant cell, such as A3=A1+A2, then Relationcell Save the A1, A2 cell, which is used to notify A1 when the A2 or A3 cell values change.

Boolean visible; Tag cells are visible, enabling Excel to hide cell functionality.

Branch Branch; Format Brush object, (Branch class does not repeat, used to save the foreground color, background color, font and other data)

3) Method Analysis

Clone () method for deep cell replication

CompareTo (cell cell) for two cell comparisons

Calculate method to realize formula analysis and calculation

SetVisible method, setting whether visible

The Save method, which converts the cell information to a string type through the StringBuffer implementation, facilitates interaction with Excel

Readbranch (Branch Branch) method to implement the cell format brush


Simple Excel cell functions can be achieved through the above analysis.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java Implementation Excel--excel cell design

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.