複数のカラムに1つのセルの


Excel文書のデータを扱う場合、1つのセルの情報を複数の列に分割し、各列を次のステップで別々に処理できるようにする場合がある.この記事では、無料の尖塔を使用する方法を紹介します.JavaのためのXLS(サードパーティ製の無料API)1つのExcelセルのテキストまたは数字を区切り文字で複数の列に分割する.区切り文字は空白、カンマ、セミコロンなどである.
インストール
方法1 : free APIをダウンロードして、それを解凍してください.XLSプロジェクトに依存するファイル.
方法2 : MavenプロジェクトにJAR依存を追加するには、POMに次の構成を追加します.XML
<repositories>
        <repository>
            <id>com.e-iceblue</id>
            <name>e-iceblue</name>
            <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
        </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.xls.free</artifactId>
        <version>3.9.1</version>
    </dependency>
</dependencies>
関連コード断片
import com.spire.xls.*;

public class splitDataIntoMultipleColumns {
    public static void main(String[] args) {
        //Load the sample document from file
        Workbook workbook = new Workbook();
        workbook.loadFromFile("source data.xlsx");

        //Get the first worksheet.
        Worksheet sheet = workbook.getWorksheets().get(0);

        //Split data into separate columns by the delimiter characters of space.
        String[] splitText = null;
        String text = null;
        for (int i = 1; i < sheet.getLastRow(); i++)
        {
            text = sheet.getRange().get(i + 1, 1).getText();
            splitText = text.split(" ");
            for (int j = 0; j < splitText.length; j++)
            {
                sheet.getRange().get(i + 1, 1 + j + 1).setText(splitText[j]);
            }
        }
        //Save to file
        workbook.saveToFile("SplitCell.xlsx", ExcelVersion.Version2013);
    }
}
結果