You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fesod.apache.org by "hooj0 (via GitHub)" <gi...@apache.org> on 2025/09/26 06:33:40 UTC

[I] 在写入excel时 converter(WriteConverterContext)或handler(CellWriteHandlerContext)能否提供注入当前行级的完整写入数据对象? [fesod]

hooj0 opened a new issue, #598:
URL: https://github.com/apache/fesod/issues/598

   ### Search before asking
   
   - [x] I searched in the [issues](https://github.com/fast-excel/fastexcel/issues) and found nothing similar.
   
   
   ### Motivation
   
   在写入excel文件时,准备好数据后,写入文件对数据进行二次转换或者简单业务逻辑处理。不想再循环进行处理。可以在数据写入单元格的时候进行二次转换或者简单业务逻辑处理,此时,业务可能需要依赖行级完整对象数据。
   示例:
   ```
   class Data {
       private int a;
       private int b;
       private int c;
       private String text;
   }
   ```
   
   在生成text单元格内容,可能需要结合数据a、b、c进行逻辑判断。
   
   
   
   
   ### Solution
   
   希望在converter(WriteConverterContext)或handler(CellWriteHandlerContext)中传入 oneRowData
   
   
   ```
   Cell cell = WorkBookUtil.createCell(row, columnIndex);
   cellWriteHandlerContext.setCell(cell);
   
   WriteHandlerUtils.afterCellCreate(cellWriteHandlerContext);
   
   cellWriteHandlerContext.setOriginalRecord(oneRowData); // 传入当前行级数据
   cellWriteHandlerContext.setOriginalValue(beanMap.get(name));
   cellWriteHandlerContext.setOriginalFieldClass(head.getField().getType());
   converterAndSet(cellWriteHandlerContext);
   
   WriteHandlerUtils.afterCellDispose(cellWriteHandlerContext);
   
   beanMapHandledSet.add(name);
   ```
   
   ### Alternatives
   
   _No response_
   
   ### Anything else?
   
   _No response_
   
   ### Are you willing to submit a PR?
   
   - [x] I'm willing to submit a PR!


-- 
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@fesod.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org
For additional commands, e-mail: commits-help@fesod.apache.org


Re: [I] 在写入excel时 converter(WriteConverterContext)或handler(CellWriteHandlerContext)能否提供注入当前行级的完整写入数据对象? [fesod]

Posted by "alaahong (via GitHub)" <gi...@apache.org>.
alaahong commented on issue #598:
URL: https://github.com/apache/fesod/issues/598#issuecomment-3338481672

   Seems it's not a mandatory requirement as below practice? Otherwise it might involve additional reference in process?
   
   ```
   public class CompositeMultipleFieldsTest {
       @Getter
       @Setter
       @ExcelIgnoreUnannotated
       static
       class Sample {
           @ExcelProperty("field1")
           private String field1;
           @ExcelProperty("field2")
           private String field2;
           @ExcelProperty("field3")
           private String field3;
   
           public String getField3() {
               return field1 + field2;
           }
       }
   
       @Test
       void test(@TempDir Path tempDir) throws Exception {
           Sample sample = new Sample();
           sample.setField1("A");
           sample.setField2("B");
           System.out.println(sample.getField3());
           FastExcel.write(tempDir.resolve("composite-multiple-fields.xlsx").toFile(), Sample.class)
                   .sheet("test")
                   .doWrite(Arrays.asList(sample));
       }
   }
   
   ```
   
   <img width="425" height="253" alt="Image" src="https://github.com/user-attachments/assets/cfb699f5-b58f-42e1-bfcd-e0bd28b28a20" />
   


-- 
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@fesod.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org
For additional commands, e-mail: commits-help@fesod.apache.org


Re: [I] Supports obtaining current row data object during writing [fesod]

Posted by "delei (via GitHub)" <gi...@apache.org>.
delei commented on issue #598:
URL: https://github.com/apache/fesod/issues/598#issuecomment-3342480664

   > 可以的
   
   Welcome. I have assigned this issue to you.


-- 
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@fesod.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org
For additional commands, e-mail: commits-help@fesod.apache.org


Re: [I] 在写入excel时 converter(WriteConverterContext)或handler(CellWriteHandlerContext)能否提供注入当前行级的完整写入数据对象? [fesod]

Posted by "delei (via GitHub)" <gi...@apache.org>.
delei commented on issue #598:
URL: https://github.com/apache/fesod/issues/598#issuecomment-3337085587

   Hi, @hooj0 
   It's a good idea! Are you willing to submit a PR?
   


-- 
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@fesod.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org
For additional commands, e-mail: commits-help@fesod.apache.org


Re: [I] Supports obtaining current row data object during writing [fesod]

Posted by "hooj0 (via GitHub)" <gi...@apache.org>.
hooj0 commented on issue #598:
URL: https://github.com/apache/fesod/issues/598#issuecomment-3342474129

   > Hi, [@hooj0](https://github.com/hooj0) It's a good idea. Are you willing to submit a PR?
   
   可以的


-- 
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@fesod.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org
For additional commands, e-mail: commits-help@fesod.apache.org