c语言读取xlsx文件?

c语言读取xlsx文件?,第1张

目前,C语言主要用于嵌入式软件的开发,很少用C语言开发PC软件。不知道帅哥是不是要在PC上用C语言 *** 作Execl文件、 *** 作原因。

既然要 *** 作,请试一下下面的方法:

A, 用Excel打开要读取的excel文件。

B, 点击Excel菜单“文件”->“另存为”,选择文件类型为“CSV(逗号分隔)”。这样,原来的excel文件会被另存为csv格式的文件,该文件是文本文件

可以用文本文件编辑工具打开的。原excel文件的每一行记录,被转换为一行文本了。一行记录各列的值,用逗号隔开了。

C, 用C语言的文件IO函数接口,读取上面文本文件即可。

The server encountered an internal error () that prevented it from fulfilling this request.

package Read

import java.io.FileInputStream

import java.io.IOException

import java.io.InputStream

import java.util.ArrayList

import java.util.List

import org.apache.poi.ss.usermodel.Cell

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.XSSFCell

import org.apache.poi.xssf.usermodel.XSSFRow

import org.apache.poi.xssf.usermodel.XSSFSheet

import org.apache.poi.xssf.usermodel.XSSFWorkbook

import bean.define

public class readxlsx {

public List<List<String>>readxl(String path) throws IOException{

InputStream is = new FileInputStream(path)

XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is)

List<List<String>>result = new ArrayList<List<String>>()

/*

//Sheet xssfSheet = null

//循环每一页,并处理当前循环页*/

for (XSSFSheet xssfSheet: xssfWorkbook) {

if (xssfSheet == null)

continue

//处理当前页,循环读取每一行

for (int rowNum = 1rowNum <= xssfSheet.getLastRowNum()rowNum++){

XSSFRow xssfRow = xssfSheet.getRow(rowNum)

int minColIx = xssfRow.getFirstCellNum()

int maxColIx = xssfRow.getLastCellNum()

List<String>rowList = new ArrayList<String>()

//List<define>list = null

//遍历该行,获取处理每个cell元素

for (int colIx = minColIxcolIx <maxColIxcolIx++) {

XSSFCell cell = xssfRow.getCell(colIx)

if(cell == null) {

define define = new define()

XSSFCell id = xssfRow.getCell(0)

XSSFCell what = xssfRow.getCell(1)

define.setId(id.getStringCellValue())

define.setWhat(what.getStringCellValue())

continue

}

rowList.add(cell.toString())

}

result.add(rowList)

}

}

return result

}

}

package com.runoob.test

import java.io.IOException

import java.util.List

import java.io.PrintWriter

import java.sql.SQLException

import javax.servlet.ServletException

import javax.servlet.http.HttpServlet

import javax.servlet.http.HttpServletRequest

import javax.servlet.http.HttpServletResponse

import Dao.dao

import bean.define

import Read.readxlsx

public class adden extends HttpServlet{

private define define

@Override

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

request.setCharacterEncoding("UTF-8")

response.setContentType("text/htmlcharset=UTF-8")

readxlsx readxlsx = new readxlsx()

String path = request.getParameter("path")

PrintWriter out = response.getWriter()

List<List<String>>list = readxlsx.readxl(path)

String id = request.getParameter("id")

String what = request.getParameter("what")

List<String>de = new define()

dao d = new dao()

for(int i=0i<list.size()i++){

de=list.get(i)

if(dao.adden(define)){

response.sendRedirect("index.jsp")

}

else out.println("读取失败")

}

out.flush()

out.close()

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/10702702.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-10
下一篇 2023-05-10

发表评论

登录后才能评论

评论列表(0条)

保存