2020 ~ REVIEWS ALL PRODUCT JVZOO

3/23/2020

Rate this posting:

https://support.office.com/en-us/article/command-line-switches-for-microsoft-office-products-079164cd-4ef5-4178-b235-441737deb3a6#ID0EAABAAA=Excel

//************
Excel.Application xlApp = new Excel.Application();

xlApp.addCommandLineParameter("/u:XXX");

xlApp.addCommandLineParameter("/p:YYY");

//************ xlworkbook = xlapp.Workbooks.Open(fileExcel, 0, true, 5, "", "", true,Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,"\t", false, false, 0, true, 1, 0);

//*********
https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.interop.excel.workbooks.open?view=excel-pia

2/20/2020

readExcell

Rate this posting:

import org.apache.poi.hssf.usermodel.*;import org.apache.poi.poifs.filesystem.POIFSFileSystem;import org.apache.poi.ss.usermodel.*;import org.apache.poi.xssf.extractor.XSSFExcelExtractor;import org.apache.poi.xssf.usermodel.XSSFCell;import org.apache.poi.xssf.usermodel.XSSFSheet;import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.*;import java.util.Iterator;import java.util.List;
public class Main {
//////////////////////////////////////

Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"sandbox_test.xlsx");
Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
Excel.Range xlRange = xlWorksheet.UsedRange;
int rowCount = xlRange.Rows.Count;
            int colCount = xlRange.Columns.Count;


////
// Theo Active (sheet đang được thao tác):
Worksheet excelWorksheet = (Worksheet)this.excelWorkbook.ActiveSheet;
Worksheet sheet = (Worksheet)xlApp.Worksheets[1];
sheet.Select(Type.Missing);
or

sheet.Activate();

//////////////
import org.apache.poi.ss.util.CellReference;
public class Excel {
    public static void convertInttoString(){
        CellReference cellReference = new CellReference(0,0);        System.out.println(cellReference.formatAsString());   
 String regex = "R([0-9]+)C([0-9]+)";
}

    public static void main(String[] args) {
        convertInttoString();    }
}
///////////

    private static final String FILE_NAME = "D:/test.xlsx";    static String handleStringCell(Cell cell) {
        String contents = cell.getRichStringCellValue().getString();        return contents;    }

    static String handleNonStringCell( Cell cell, DataFormatter formatter) {
        String contents = "";        CellType type = cell.getCellTypeEnum();        if (type == CellType.FORMULA) {
            type = cell.getCachedFormulaResultTypeEnum();        }

        if (type == CellType.NUMERIC) {
            CellStyle cs = cell.getCellStyle();
            if (cs != null && cs.getDataFormatString() != null) {
                contents = formatter.formatRawCellContents(
                        cell.getNumericCellValue(), cs.getDataFormat(), cs.getDataFormatString());            }
        }else{
            // No supported styling applies to this cell             contents = ((XSSFCell)cell).getRawValue();        }
       return contents;    }
    public static void main(String[] args) {
        //////////////////////////////////////////        DataFormatter dataFormatter = new DataFormatter();//////////////////////////////////////////
        try {

            FileInputStream excelFile = new FileInputStream(new File(FILE_NAME));            Workbook workbook = new XSSFWorkbook(excelFile);            Sheet datatypeSheet = workbook.getSheetAt(0);            Iterator<Row> iterator = datatypeSheet.iterator();
            while (iterator.hasNext()) {

                Row currentRow = iterator.next();                Iterator<Cell> cellIterator = currentRow.iterator();


                while (cellIterator.hasNext()) {

                    Cell currentCell = cellIterator.next();                    currentCell.getAddress();                  //  HSSFName name = (HSSFName) workbook.getNameAt(0);
//////////////////////////////////////////                    String cellStringValue = dataFormatter.formatCellValue(currentCell);                    System.out.println(cellStringValue);                    XSSFExcelExtractor a = new XSSFExcelExtractor((XSSFWorkbook) workbook);                    a.getText();
                    System.out.println("===================="+dataFormatter.formatCellValue(currentCell)+"============================");                    // Rows and cells
                    // Is it a formula one?                    if(currentCell.getCellTypeEnum() == CellType.FORMULA) {
                        if (currentCell.getCellFormula()!="") {
                            String contents = currentCell.getCellFormula();                            System.out.println(contents);                        } else {
                            if (currentCell.getCachedFormulaResultTypeEnum() == CellType.STRING) {
                                handleStringCell(currentCell);                            } else {
                                handleNonStringCell(currentCell, dataFormatter);                            }
                        }
                    } else if(currentCell.getCellTypeEnum() == CellType.STRING) {
                        handleStringCell( currentCell);                    } else {
                        handleNonStringCell(currentCell, dataFormatter);                    }

//////////////////////////////////////////
                }
                System.out.println();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();        } catch (IOException e) {
            e.printStackTrace();        }

    }
}


//////////pom
<dependency>    <groupId>org.apache.poi</groupId>    <artifactId>poi-ooxml</artifactId>    <version>4.1.2</version></dependency>

1/14/2020

Registry

Rate this posting:

1/01/2020

dragScroll

Rate this posting:

package test;import javafx.animation.KeyFrame;import javafx.animation.Timeline;import javafx.application.Application;import javafx.geometry.Orientation;import javafx.scene.Node;import javafx.scene.Scene;import javafx.scene.input.MouseEvent;import javafx.scene.input.ScrollEvent;import javafx.scene.control.Label;import javafx.scene.control.ScrollBar;import javafx.scene.control.ScrollPane;import javafx.scene.input.ClipboardContent;import javafx.scene.input.DragEvent;import javafx.scene.input.Dragboard;import javafx.scene.input.TransferMode;import javafx.scene.layout.BorderPane;import javafx.scene.layout.VBox;import javafx.stage.Stage;import javafx.util.Duration;
public class dragdrop extends Application {
    private ScrollPane sp;    private Timeline scrolltimeline = new Timeline();    private double scrollVelocity = 0;
    boolean dropped;
    //Higher speed value = slower scroll.    int speed = 200;
    @Override    public void start(Stage primaryStage) throws Exception {
        BorderPane root = new BorderPane();
        sp = new ScrollPane();        sp.setPrefSize(300, 300);        sp.setStyle("-fx-background-color:red");
        VBox outer = new VBox(sp);
        VBox innerBox = new VBox();        innerBox.setPrefSize(2000,1000);
        sp.setContent(innerBox);
        root.setCenter(outer);
        Label dragMe = new Label("drag me to edge!\n"+"or drop me in scrollpane!");        root.setTop(dragMe);
        setupScrolling();
        dragMe.setOnDragDetected((MouseEvent event) ->{
            Dragboard db = dragMe.startDragAndDrop(TransferMode.ANY);            db.setDragView(((Node) event.getSource()).snapshot(null, null));
            ClipboardContent content = new ClipboardContent();            content.putString((dragMe.getText()));
            db.setContent(content);            event.consume();        });

        Scene scene = new Scene(root, 640, 480);        primaryStage.setScene(scene);        primaryStage.show();    }

    private void setupScrolling() {
        //set timeline        scrolltimeline.setCycleCount(Timeline.INDEFINITE);        scrolltimeline.getKeyFrames().add(new KeyFrame(Duration.millis(20), (ActionEvent) -> { dragScroll();}));
        sp.setOnDragExited((DragEvent event) -> {

            //set vận tốc            if (event.getY() > 0) {
                scrollVelocity = 1.0 / speed;            }
            else {
                scrollVelocity = -1.0 / speed;
            }

//            if (event.getX() > 300) {//                scrollVelocity = 1.0 / speed;//            }//            else {//                scrollVelocity = -1.0 / speed;//            }            if (!dropped){
                scrolltimeline.play();            }

        });
        sp.setOnDragEntered(event -> {
            scrolltimeline.stop();            dropped = false;        });        sp.setOnDragDone(event -> {
            System.out.print("test");            scrolltimeline.stop();        });        sp.setOnDragDropped((DragEvent event) ->{
            Dragboard db = event.getDragboard();            ((VBox) sp.getContent()).getChildren().add(new Label(db.getString()));            scrolltimeline.stop();            event.setDropCompleted(true);            dropped = true;

        });
        sp.setOnDragOver((DragEvent event) ->{
            event.acceptTransferModes(TransferMode.MOVE);        });

        sp.setOnScroll((ScrollEvent event)-> {
            scrolltimeline.stop();        });
        sp.setOnMouseClicked((MouseEvent)->{
            System.out.println(scrolltimeline.getStatus());
        });
    }
    private void dragScroll() {
        //ScrollBar sb = getVerticalScrollbar();        ScrollBar sb = getHORIZONTALScrollbar();
        if (sb != null) {
            double newValue = sb.getValue() + scrollVelocity;            newValue = Math.min(newValue, 1.0);            newValue = Math.max(newValue, 0.0);            sb.setValue(newValue);        }
    }

    private ScrollBar getVerticalScrollbar() {
        ScrollBar result = null;        for (Node n : sp.lookupAll(".scroll-bar")) {
            if (n instanceof ScrollBar) {
                ScrollBar bar = (ScrollBar) n;                if (bar.getOrientation().equals(Orientation.VERTICAL)) {
                    result = bar;                }
            }
        }
        return result;    }
    private ScrollBar getHORIZONTALScrollbar() {
        ScrollBar result = null;        for (Node n : sp.lookupAll(".scroll-bar")) {
            if (n instanceof ScrollBar) {
                ScrollBar bar = (ScrollBar) n;                if (bar.getOrientation().equals(Orientation.HORIZONTAL)) {
                    result = bar;                }
            }
        }
        return result;    }

    public static void main(String[] args) {
        launch(args);    }

}