String body= FileUtil.readString("{\n" + " \"pageNo\": 1,\n" + " \"pageSize\": 50,\n" + " \"param\": {\n" + " \"workTypes\": [\n" + " \"TRANSFER\",\n" + " \"BEFORE_APPEND\",\n" + " \"AFTER_APPEND\",\n" + " \"SELF\",\n" + " \"OPINION\",\n" + " \"AGENT\",\n" + " \"ORIGINATOR_SUBMIT\"\n" + " ]\n" + " }\n" + "}","UTF-8");把这段代码转换成正确格式
时间: 2023-07-25 21:03:56 浏览: 200
你可以将这段代码转换为以下格式:
```java
String body = FileUtil.readString("{\n" +
" \"pageNo\": 1,\n" +
" \"pageSize\": 50,\n" +
" \"param\": {\n" +
" \"workTypes\": [\n" +
" \"TRANSFER\",\n" +
" \"BEFORE_APPEND\",\n" +
" \"AFTER_APPEND\",\n" +
" \"SELF\",\n" +
" \"OPINION\",\n" +
" \"AGENT\",\n" +
" \"ORIGINATOR_SUBMIT\"\n" +
" ]\n" +
" }\n" +
"}", "UTF-8");
```
相关问题
String type = FileUtil.extName(originalFilename); 无法解析 'FileUtil' 中的方法 'extName'
这个问题可能是因为在你的代码中没有导入 `FileUtil` 类或者没有正确地使用该类。请确保你已经正确地导入了该类,可以使用以下代码导入:
```java
import cn.hutool.core.io.FileUtil;
```
另外,请确保你的项目中包含了 Hutool 库,可以在项目中添加以下 Maven 依赖:
```xml
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.5.10</version>
</dependency>
```
如果你使用的是 Gradle,可以添加以下依赖:
```
implementation 'cn.hutool:hutool-all:5.5.10'
```
如果仍然无法解决问题,请提供更多的代码和错误信息。
try { File excelFile = FileUtil.loadTemp(excel.getOriginalFilename(), excel.getInputStream()); Workbook workbook = new Workbook(excelFile.getAbsolutePath()); Worksheet firstWorksheet = workbook.getWorksheets().get(0); firstWorksheet.autoFitRows(); firstWorksheet.autoFitColumns(); if (image != null) { File imageFile = FileUtil.loadTemp(image.getOriginalFilename(), image.getInputStream()); int pictureIndex = firstWorksheet.getPictures().add(1, 1, imageFile.getAbsolutePath()); int maxRow = firstWorksheet.getCells().getMaxDataRow(); int maxColumn = firstWorksheet.getCells().getMaxDataColumn(); Picture picture = firstWorksheet.getPictures().get(pictureIndex); int pictureTopRow = maxRow + 2; int pictureLeftColumn = 0; picture.setUpperLeftRow(pictureTopRow); picture.setUpperLeftColumn(pictureLeftColumn); double rowHeight = picture.getHeightInch() * 72; if (rowHeight > 409) { rowHeight = 409; } firstWorksheet.getCells().setRowHeight(pictureTopRow, rowHeight); double pictureWidth = picture.getWidthInch() * 72; int pictureRightColumn = pictureLeftColumn + (int) (pictureWidth / 8.43); for (int column = pictureLeftColumn; column <= pictureRightColumn; column++) { firstWorksheet.getCells().setColumnWidth(column, 8.43); } } File tempFile = FileUtil.newTempFile(DateUtil.today().concat(ExcelTypeEnum.XLSX.getValue())); workbook.save(tempFile.getAbsolutePath(), com.aspose.cells.SaveFormat.XLSX); FileInputStream stream = new FileInputStream(tempFile); FileUtil.downFile(response, tempFile.getName(), stream); } catch (Exception e) { log.error("业务异常:{}", e.getMessage()); MessageException.throwMsg("业务异常"); } 我需要设置表格自适应宽度
在上述代码中,已经使用了 `firstWorksheet.autoFitRows();` 和 `firstWorksheet.autoFitColumns();` 来自适应表格的行高和列宽。如果你想要更精确地控制某一列或某几列的宽度,可以使用 `setColumnWidth` 方法,示例如下:
```
// 设置第1列的宽度为20
firstWorksheet.getCells().setColumnWidth(0, 20);
// 设置第2列到第5列的宽度为15
for (int column = 1; column <= 4; column++) {
firstWorksheet.getCells().setColumnWidth(column, 15);
}
```
可以根据需要自己调整列宽大小。注意,这里的单位是字符宽度,不是像素或者英寸。
阅读全文