You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/09/02 01:55:29 UTC
[GitHub] [incubator-seatunnel] TyrantLucifer commented on a diff in pull request #2585: [Feature][ConnectorV2]add file excel sink
TyrantLucifer commented on code in PR #2585:
URL: https://github.com/apache/incubator-seatunnel/pull/2585#discussion_r961216601
##########
seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/sink/util/ExcelGenerator.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.seatunnel.connectors.seatunnel.file.sink.util;
+
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.api.table.type.SqlType;
+import org.apache.seatunnel.common.utils.JsonUtils;
+
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.CreationHelper;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ExcelGenerator {
+ private Workbook wb;
+ private CellStyle wholeNumberCellStyle;
+ private CellStyle stringCellStyle;
+ private int row = 0;
+ private List<Integer> sinkColumnsIndexInRow;
+ private SeaTunnelRowType seaTunnelRowType;
+
+ public ExcelGenerator(List<Integer> sinkColumnsIndexInRow, SeaTunnelRowType seaTunnelRowType) {
+ this.sinkColumnsIndexInRow = sinkColumnsIndexInRow;
+ this.seaTunnelRowType = seaTunnelRowType;
+ wb = new XSSFWorkbook();
+ Sheet st = wb.createSheet("Sheet1");
+ Row row = st.createRow(this.row);
+ for (Integer i : sinkColumnsIndexInRow) {
+ String fieldName = seaTunnelRowType.getFieldName(i);
+ row.createCell(i).setCellValue(fieldName);
+ }
+
+ wholeNumberCellStyle = createStyle(wb, "General");
+ stringCellStyle = createStyle(wb, "@");
+ this.row += 1;
+ }
+
+ public void writeData(SeaTunnelRow seaTunnelRow) {
+ Sheet st = wb.getSheet("Sheet1");
Review Comment:
How about treated `st` as a class attribute, when a SeaTunnelRow needs be consumed `createSheet` will be invoked. Of course, I have no detailed source code understanding, in each write whether to obtain a sheet object needs a double check.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org