Document Solutions for Excel, Java Edition | Document Solutions
Features / Worksheet / Range Operations / Set Values to a Range
In This Topic
    Set Values to a Range
    In This Topic

    DsExcel Java enables users to specify custom values for the cell range by using the methods of the IRange interface.

    In order to set custom values to cell ranges in the worksheet, refer to the following example code.

    Java
    Copy Code
    worksheet.getRange("A:F").setColumnWidth(15);
    
    Object data = new Object[][] { { "Name", "City", "Birthday", "Eye color", "Weight", "Height" },
            { "Richard", "New York", new GregorianCalendar(1968, 5, 8), "Blue", 67, 165 },
            { "Nia", "New York", new GregorianCalendar(1972, 6, 3), "Brown", 62, 134 },
            { "Jared", "New York", new GregorianCalendar(1964, 2, 2), "Hazel", 72, 180 },
            { "Natalie", "Washington", new GregorianCalendar(1972, 7, 8), "Blue", 66, 163 },
            { "Damon", "Washington", new GregorianCalendar(1986, 1, 2), "Hazel", 76, 176 },
            { "Angela", "Washington", new GregorianCalendar(1993, 1, 15), "Brown", 68, 145 } };
    
    // set two-dimension array value to range A1:F7
    worksheet.getRange("A1:F7").setValue(data);
    
    // return a two-dimension array when get range A1:B7's value.
    Object result = worksheet.getRange("A1:B7").getValue();