コーディングが行き詰まっており、あなたの助けが必要です。
まず、クラスの下に配列変数があります。
エクセルから値を取得し、以下のように nodename 配列内に配置します。以下のコードを短縮しました。
次のクラス Readexcel も ConfigGenerator クラスの下にあります。
class ReadExcel {
private String inputFile;
public void setInputFile(String inputFile) {
this.inputFile = inputFile;
}
public void read() throws IOException {
File inputWorkbook = new File(inputFile);
Workbook nodes;
try {
nodes = Workbook.getWorkbook(inputWorkbook);
// Get the first sheet
Sheet nodessheet = nodes.getSheet(1);
String[] nodename = new String[nodessheet.getRows()];
for (int i = 1; i < nodessheet.getRows(); i++) {
int j = 0;
Cell x1a = nodessheet.getCell(0, i);
nodename[j] = x1a.getContents();
j++;
// System.out.println(nodename[j]);
}
} catch (BiffException e) {
// e.printStackTrace();
}
}
}
しかし、私の問題は、ボタン アクションからこの変数に到達することです。
public class ConfigGenerator extends javax.swing.JFrame {
public ConfigGenerator() {
initComponents();
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
}
private void generateActionPerformed(java.awt.event.ActionEvent evt) {
try {
Writer output = null;
for (String name: Generator.ConfigGenerator.ReadExcel.nodename[????]){
System.out.println(name);
}
output.close();
System.out.println("Your files has been written.");
} catch (IOException ex) {
Logger.getLogger(ConfigGenerator.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
疑問符を追加した部分は、過去 2 日間の問題ですが、その配列から値を取得できませんでした。最初に配列の長さを取得し、次に値を取得する必要があります:)事前にご協力いただきありがとうございます。
セクション全体にコードを追加して質問を編集しました。