首页 > 其他分享 >【待解决】Typed variable declaration : Class: Workbook not found in namespace

【待解决】Typed variable declaration : Class: Workbook not found in namespace

时间:2023-08-21 16:15:10浏览次数:34  
标签:style2 Typed namespace apache createCell poi Workbook import setCellValue

需求

接口需要导入excel,自动生成excel文件以及数据

问题

idea中可以成功

依赖

        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <!--<version>4.1.2</version>-->
            <version>5.2.2</version>
        </dependency>

 

代码复制到beanshell,或者idea中maven项目打jar包放到jmeter的lib/ext目录下,都报错:

ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel. . . . '' : Typed variable declaration : Class: Workbook not found in namespace

ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval	Sourced file: inline evaluation of: ``import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel. . . . '' : Typed variable declaration : Class: Workbook not found in namespace

 

导了包也一样报错,和这个问题一样:https://stackoverflow.com/questions/54341188/getting-the-follwoing-error-typed-variable-declaration-class-workbook-not-fo

 

有没有哪位小伙伴遇到过?

 

附代码

//import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileOutputStream;
import java.io.IOException;


        // 创建一个新的工作簿
        Workbook workbook = new XSSFWorkbook();

        // 创建一个新的工作表
        Sheet sheet = workbook.createSheet("Sheet1");

        // 创建新行
        Row row = sheet.createRow(0);

        // 创建单元格样式
        CellStyle style = workbook.createCellStyle();

        // 给style添加水平居中对齐
        style.setAlignment(HorizontalAlignment.CENTER);

        // ===设置字体样式===
        // 创建字体对象
        Font font = workbook.createFont();
        // 字体加粗
        font.setBold(true);
        // 设置字体大小
        font.setFontHeightInPoints((short) 20);
        // 设置字体类型
        font.setFontName("宋体");
        // 给style添加字体样式
        style.setFont(font);


        // 合并第二行的0-5列
        Cell cell = row.createCell(0);
        // 给单元格设置内容
        cell.setCellValue("供应商导入");
        // 给单元格设置样式
        cell.setCellStyle(style);
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));



        // 创建单元格样式
        CellStyle style2 = workbook.createCellStyle();
        // ===设置字体样式===
        // 创建字体对象
        Font font2 = workbook.createFont();
        // 字体加粗
        font2.setBold(true);
        // 设置字体大小
        font2.setFontHeightInPoints((short) 11);
        // 设置字体类型
        font2.setFontName("宋体");
        style2.setFont(font2);

        // 创建新行
        Row row2 = sheet.createRow(1);
        Cell cell0 = row2.createCell(0);
        cell0.setCellStyle(style2);
        cell0.setCellValue("*供应商分类编码");
        Cell cell1=row2.createCell(1);
        cell1.setCellStyle(style2);
        cell1.setCellValue("*供应商编码");
        Cell cell2=row2.createCell(2);
        cell2.setCellStyle(style2);
        cell2.setCellValue("*供应商名称");
        Cell cell3=row2.createCell(3);
        cell3.setCellStyle(style2);
        cell3.setCellValue("*供应商简称");
        Cell cell4=row2.createCell(4);
        cell4.setCellStyle(style2);
        cell4.setCellValue("*助记码");
        Cell cell5=row2.createCell(5);
        cell5.setCellStyle(style2);
        cell5.setCellValue("*分管部门编码");
        Cell cell6=row2.createCell(6);
        cell6.setCellStyle(style2);
        cell6.setCellValue("税率");


        for (int i = 0; i < 1; i++) {
            Row rowi = sheet.createRow(i+2);
            for (int j = 0; j < 7 ; j++) {
                if (j==6){
                    rowi.createCell(j).setCellValue(3);
                    continue;
                }
                rowi.createCell(j).setCellValue("test"+j);
            }
        }


        // 保存工作簿到文件
        String filename = "test.xlsx";
        FileOutputStream fos = new FileOutputStream(filename);
        workbook.write(fos);
        fos.close();

        System.out.println("工作簿已保存到文件:" + filename);

  

标签:style2,Typed,namespace,apache,createCell,poi,Workbook,import,setCellValue
From: https://www.cnblogs.com/uncleyong/p/17646240.html

相关文章

  • 关于spring中的TypeDescriptor、ResolvableType功能说明
    TypeDescriptor:类型描述符该类位于org.springframework.core.convert包下,convert包主要用于类型转换相关功能,在类型转换过程中,通常需要从一个类型转为另一个类型,而Java类型包含基本类型,数组、集合、泛型以及普通类型,该类试图将这些不同的类型使用一种统一的类型来表示,因此方法中提......
  • [React Typescript] React namespace
    export=React;exportasnamespaceReact;declarenamespaceReact{////ReactElements//----------------------------------------------------------------------typeElementType<P=any>={[KinkeyofJSX.I......
  • [React Typescript] Well typed a React Context provider
    importReactfrom"react";import{Equal,Expect}from"../helpers/type-utils";constcreateRequiredContext=<Textendsany>()=>{constcontext=React.createContext<T|null>(null);constuseContext=<Te......
  • 执行kubeadm 出现 FATAL: the ConfigMap "kubeadm-config" in the kube-system namesp
    现象: [upgrade/config]Makingsuretheconfigurationiscorrect:[upgrade/config]Readingconfigurationfromthecluster...[upgrade/config]FYI:Youcanlookatthisconfigfilewith'kubectl-nkube-systemgetcmkubeadm-config-oyaml'[upgrade/c......
  • 快速解决 const 与 typedef 类型组合时 ,const修饰谁的问题
    C++使用typedef给复合类型定义别名时,与const结合会产生看似“令人困惑”的类型推定,例如typedefchar*pstring;constpstringcstr=0;constpstring*ps;cstr到底是什么类型?如果直接把pstring展开成char*,就会认为cstr是constchar*类型,从而认为cstr是一个指向const......
  • java XSSFWorkbook excel 公式计算
    excel公式计算//创建一个工作薄XSSFWorkbookworkbook=newXSSFWorkbook();//如果是最后一列添加一个求和计算,将结果放到同一列最后一个。dataLists数据列表XSSFSheetsheet=workbook.getSheet(replaceSpecStr(sheetNames.get(0)));Rowrow......
  • C语言 typedef 定义 struct 变量
    typedefstructnode{ datatypedata; structnode*next;}linknode,*linklist;创建单链表linklistL;//等价于structnode*L可以理解为,通过typedef,将structnode*替换为linklist当我们在使用LinkListL定义变量时,实际上就是在使用structnode*L定义变量使得以后......
  • C# NPOI 合并多个工作簿(Workbook)的第一个工作表(Sheet)
    最近在工作中用到了一些NPOI,发现很好用,但是说明文档比较少,好多人都直接去参考POI?希望NPOI作者或者某位使用NPOI较多的大神能完善相关文档,让这个好用的工具更加好用。回到正题本次项目中主要用到合并多个工作簿(Workbook)的第一个工作表(Sheet)这个功能,一开始的做法是利用XSSFW......
  • 3.声明式API及指令式命令创建namespace、pod、service
    应用编排运行在kubernetes上的条件1、以容器化形式,得有可用的Image2、编排、调度、运行应用的最小单元是pod3、Controller模式(控制器模式)4、声明式API声明式API声明式API:声明资源对象的终态,达成终态的依赖项是Controller声明多个资源终态:以应用为中心工作负载型......
  • Exception: Not found: 'python/cv2/py.typed'
    CopyingfilesfromCMakeoutputcreatingdirectory_skbuild/linux-x86_64-3.6/cmake-install/cv2copying_skbuild/linux-x86_64-3.6/cmake-install/python/cv2/python-3/cv2.abi3.so->_skbuild/linux-x86_64-3.6/cmake-install/cv2/cv2.abi3.socopying_skbuild/linu......