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

📄 cellfrmt.java

📁 The jxcell allows any Java developer to automate any manual spreadsheet process within their organiz
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

import com.jxcell.View;
import com.jxcell.CellFormat;

import java.lang.*;
import java.awt.Color;

public class CellFrmt
{ 
    //Global constants for the Format types
    public final int SIMPLE = 0;
    public final int CLASSIC1 = 1;
    public final int CLASSIC2 = 2;
    public final int CLASSIC3 = 3;
    public final int ACCOUNTING1 = 4;
    public final int ACCOUNTING2 = 5;
    public final int ACCOUNTING3 = 6;
    public final int LIST1 = 7;
    public final int LIST2 = 8;
    public final int LIST3 = 9;
    public final int COLORFUL1 = 10;
    public final int COLORFUL2 = 11;
    public final int COLORFUL3 = 12;
    public final int EFFECTS3D1 = 13;

    View m_view;
    CellFormat cfmt;
    
    CellFrmt(View view1)
    {
            m_view = view1;

            try{
                m_view.setSelection(1,1,7,5);
            }
            catch (com.jxcell.CellException e){
                System.out.println(e.getMessage());
            }
    }
    
    String hdrRange = null;
    String  ftrRange = null, 
            colRange = null, 
            bodyRange = null, 
            savedSelection = null,
            eRange,
            StartRange;
    
    //FrmtType -- format type ie Simple, Accounting etc.
    public void FormatCells(int FrmtType){
        
        int StartRow = 0, StartCol = 0 , EndRow = 0, EndCol = 0;
        String fileName, dirName;
              
        dirName = System.getProperty("user.dir");
        fileName = "book.xls";

        try
        {
            m_view.read(dirName + "\\" + fileName);
            m_view.setSelection(1,1,7,5);
            m_view.setShowGridLines(false);
            cfmt = m_view.getCellFormat();
            m_view.editClear(View.eClearFormats);

            savedSelection = m_view.getSelection();

        }
        catch (com.jxcell.CellException e){
            System.out.println(e.getMessage());
        }
        catch (java.io.IOException io){
              System.out.println(io.getMessage());
        }

        try
        {
            StartRow = m_view.getSelStartRow();
            StartCol = m_view.getSelStartCol();
            EndRow = m_view.getSelEndRow();
            EndCol = m_view.getSelEndCol();
            StartRange = m_view.formatRCNr(StartRow, StartCol, false);
            eRange = m_view.formatRCNr(StartRow, EndCol, false);
            hdrRange = StartRange + ":" + eRange;
            
            eRange = m_view.formatRCNr(EndRow, StartCol, false);
            colRange = StartRange + ":" + eRange;
            
            StartRange = m_view.formatRCNr(EndRow, StartCol, false);
            eRange = m_view.formatRCNr(EndRow, EndCol, false);
            ftrRange = StartRange + ":" + eRange;
            
            StartRange = m_view.formatRCNr(StartRow + 1, StartCol + 1, false);
            eRange = m_view.formatRCNr(EndRow- 1, EndCol, false);
            bodyRange = StartRange + ":" + eRange;
            
                
            m_view.setSelection (hdrRange);
            cfmt.setTopBorder(CellFormat.eBorderMedium);
            cfmt.setBottomBorder(CellFormat.eBorderMedium);
            AdjustFont(java.awt.Color.black.getRGB(), true, false, false, cfmt);
            cfmt.setHorizontalAlignment(CellFormat.eHorizontalAlignmentRight);
            cfmt.setVerticalAlignment(CellFormat.eVerticalAlignmentBottom);
               
            m_view.setCellFormat(cfmt);
            //m_view.update();
              
            m_view.setSelection (ftrRange);
            cfmt.setBottomBorder(CellFormat.eBorderMedium);
            cfmt.setTopBorder(CellFormat.eBorderThin);
            m_view.setCellFormat(cfmt);
            //m_view.update();
            
               
            }
        catch (com.jxcell.CellException e){
                System.out.println("Can't set border " + e.getMessage());
        }
        
        if (FrmtType == SIMPLE)
        {
            try
            {
                m_view.setSelection(colRange);
                m_view.setCellFormat(cfmt);

                m_view.setSelection (hdrRange);
               cfmt.setTopBorder(CellFormat.eBorderMedium);
               cfmt.setBottomBorder(CellFormat.eBorderMedium);
               AdjustFont(java.awt.Color.black.getRGB(), true, false, false, cfmt);
               cfmt.setHorizontalAlignment(CellFormat.eHorizontalAlignmentRight);
               cfmt.setVerticalAlignment(CellFormat.eVerticalAlignmentBottom);
               m_view.setCellFormat(cfmt);
               //m_view.update();
               
               m_view.setSelection (ftrRange);
               cfmt.setBottomBorder(CellFormat.eBorderMedium);
               cfmt.setTopBorder(CellFormat.eBorderThin);
               m_view.setCellFormat(cfmt);
               //m_view.update();
               
            }
            catch (com.jxcell.CellException e)
            {
                System.out.println("Can't set border " + e.getMessage());
            }
        }
        else if (FrmtType == CLASSIC1)
        {
            
            try{
                
                m_view.setSelection(colRange);
                cfmt.setTopBorder(CellFormat.eBorderNone);
                cfmt.setBottomBorder(CellFormat.eBorderNone);
                cfmt.setRightBorder(CellFormat.eBorderThin);
                m_view.setCellFormat(cfmt);
                //m_view.update();

                cfmt.setRightBorder(CellFormat.eBorderNone);
                m_view.setSelection(hdrRange);
                cfmt.setTopBorder(CellFormat.eBorderMedium);
                cfmt.setBottomBorder(CellFormat.eBorderThin);
                AdjustFont(java.awt.Color.black.getRGB(), false, true, false, cfmt);
                cfmt.setHorizontalAlignment(CellFormat.eHorizontalAlignmentRight);
                cfmt.setVerticalAlignment(CellFormat.eVerticalAlignmentBottom);
                m_view.setCellFormat(cfmt);
                //m_view.update();
                
                m_view.setSelection(ftrRange);
                cfmt.setTopBorder(CellFormat.eBorderThin);
                cfmt.setBottomBorder(CellFormat.eBorderMedium);
                m_view.setCellFormat(cfmt);
               // m_view.update();
                
            }
            catch (com.jxcell.CellException e){
                System.out.println(e.getMessage());
            }

        }
        else if (FrmtType == CLASSIC2)
        {
            Classic2(cfmt);
        }
        else if (FrmtType == CLASSIC3)
        {
            Classic3(cfmt);
        }
        else if (FrmtType == ACCOUNTING1)
        {   
            Accounting1(cfmt);
        }
        else if (FrmtType == ACCOUNTING2)
        {
            Accounting2(cfmt);
        }
        else if (FrmtType == ACCOUNTING3)
        {
            Accounting3(cfmt);
        }
        else if (FrmtType == LIST1)
        {
            List1(cfmt);
        }
        else if (FrmtType == LIST2)
        {
            List2(cfmt);
        }
        else if (FrmtType == LIST3)
        {
            List3(cfmt);
        }
        else if (FrmtType == COLORFUL1)
        {
            Colorful1(cfmt);
        }
        else if (FrmtType == COLORFUL2)
        {
            Colorful2(cfmt);
        }
        else if (FrmtType == COLORFUL3)
        {
            Colorful3(cfmt);
        }
        
        else if (FrmtType == EFFECTS3D1)
        {
            Effects3D1(cfmt);
        }

        m_view.setRepaint(true);
        m_view.repaint();
        
    }//FormatCells
 
    private void Classic2(CellFormat cellFmt){
        
        short nPattern;
        try{
            
           m_view.setSelection(colRange);
           AdjustFont(java.awt.Color.black.getRGB(), true, false, false, cellFmt);
           m_view.setCellFormat(cellFmt);
           //m_view.update();
            
           m_view.setSelection(hdrRange);
           cellFmt.setTopBorder(CellFormat.eBorderMedium);
           cellFmt.setBottomBorder(CellFormat.eBorderThin);
           AdjustFont(java.awt.Color.white.getRGB(), false, false, false, cellFmt);
           nPattern = 1;
           cellFmt.setPattern(nPattern);
           cellFmt.setPatternFG(java.awt.Color.magenta);
           cellFmt.setPatternBG(java.awt.Color.magenta);
           cellFmt.setHorizontalAlignment(CellFormat.eHorizontalAlignmentRight);
           cellFmt.setVerticalAlignment(CellFormat.eVerticalAlignmentBottom);
           m_view.setCellFormat(cellFmt);
           //m_view.update();

           m_view.setSelection(ftrRange);
           cellFmt.setBottomBorder(CellFormat.eBorderMedium);
           cellFmt.setTopBorder(CellFormat.eBorderThin);
           m_view.setCellFormat(cellFmt);
           //m_view.update();
           
                
        }
        catch (com.jxcell.CellException e){
            System.out.println(e.getMessage());
        }
        
    } //Classic2
    
    private void Classic3 (CellFormat cellFmt){

        try{
            m_view.setSelection(hdrRange);
            cellFmt.setTopBorder(CellFormat.eBorderMedium);
            cellFmt.setBottomBorder(CellFormat.eBorderMedium);
            AdjustFont(java.awt.Color.white.getRGB(), true, true, false, cellFmt);
            AlignRight(cellFmt);
            SetSolidPattern(cellFmt, m_view.getPaletteEntry(11).getRGB(), java.awt.Color.black.getRGB());
            m_view.setCellFormat(cellFmt);
            //m_view.update();

⌨️ 快捷键说明

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