xlsx 相关问题

xlsx是使用默认格式Microsoft Excel 2007或更高版本创建的文件的文件扩展名。

如何在 python 中检测 xlsx 文件是否受密码保护?

我需要检测 excel 文件是否受密码保护。如果密码受保护,请向用户询问密码。 我如何在 python 中执行此操作? 我在网上看了一点,...

回答 1 投票 0

在 Node.js 中使用 SheetJS 读取 excel 文件时出现问题

我正在尝试开发一个简单的 Node.js 应用程序,该应用程序采用 excel (xlsx) 输入文件并将工作簿中的所有工作表作为单独的 csv 文件写出,这些文件以它们来自的工作表命名。我习惯了

回答 0 投票 0

为什么在 python merge 中对带有 pandas 的 xlsx 文件使用连接语句时得到不同的输出

我正在尝试读取 2 个 xlsx 文件并尝试将数据附加到单个 xls 文件。示例输入: f1 中的数据: 身份证号码 a1 b1 c1 a2 b2 c2 k1 k2 k3 f2 中的数据: jd kd rd md nd pd a1 b1 c1 d1 ...

回答 0 投票 0

替换 `to_xls` gem 以生成 'xlsx' 文件

我有一个 Rails 应用程序,我在其中使用 to_xls gem 生成“xls”文件,但现在我想生成“xlsx”文件。 所以我想问问是否有办法生成“xlsx”...

回答 0 投票 0

如何在 SheetJS 的 xlsm 工作簿中将新行附加到现有工作表

我正在尝试将新行附加到现有的 Excel 工作表中,但没有成功。 当我使用 writeFile 而不是 write 函数时,它会创建一个包含所有数据的全新文件,但我想附加...

回答 3 投票 0

使用样式将 html 表导出到 xlsx

如何将 Angular 中 ID 为“mytable”的 HTML 表格转换为扩展名为 xlsx 的 Excel 文件,同时保留 HTML 文件中定义的样式(例如边框和颜色)(

回答 0 投票 0

在 C# 的 Excel 函数中导入时,我无法从 xlsx 中识别空单元格

我正在尝试将 .xlsx 文件导入数据库。我在导入函数中遇到了一个问题:我调用了一个函数来创建一行中的元素列表,每个单元格中的列表...

回答 0 投票 0

如何从 R 中插入 1 行 en sheet excel?

我是新手,使用包“xlsx”: 白<- openxlsx::loadWorkbook(file = "test.xlsx") sheets <- getSheets(wb) sheet <- sheets[['0923301_']] rows <- getRows(sheet)#all...

回答 0 投票 0

在我使用 python 读取 xlsx 文件并将其显示在 linux 终端后显示隐藏行

以下是我的 python 代码,用于在 linux 终端中显示 xlsx 文件的一部分: 将熊猫导入为 pd 2 require_cols=[1,3,6,7,8,9] 3 df=pd.read_excel('NGXP_6_2_2_dimensions.xlsx',

回答 0 投票 0

使用xlsx(用于将json数组转换为excel格式)时将日期从“dd-mm-yyyy hh:mm:ss”格式化为“dd-mm-yyyy”

我正在使用 xlsx npm 将对象数组转换为 Excel 格式,然后将数据转换为 blob 并使用文件保护程序以 Excel 格式下载。在我的用户界面中,我有一个按钮可以下载电子...

回答 1 投票 0

R xlsx Excel 数字格式

我创建了一个工作簿 (createWorkbook) 并设置了标题的格式,但是如何设置数字值的格式以便在我写入/保存到 Excel 时得到以下信息: 对于第一个字段,例如 ...

回答 1 投票 0

没有 Excel 编写器‘xlwt’

xlwt 已安装,在 python 3.9 上 current_dir = os.path.dirname(__file__) pathXLSX = os.path.join(current_dir,'moveData',weapon[0]+".xlsx") pathXLS = os.path.join(current_dir,'

回答 0 投票 0

如何使用 XLSX npm 包添加带有颜色的自定义标头

我是使用 XLSX 包的新手,我不太确定如何创建特定的标题,包括颜色和特定于组的列。 我需要做一些事情作为视觉示例 在标题下,我可以有

回答 2 投票 0

如何从外部 Excel 文件获取行和列 - JAVA?

我试图从外部 Excel 文件 (.xlsx) 中读取一些数据到我的 Java 代码(IDE:Eclipse)中,但我不明白如何获取列。 有人可以帮助我吗?多谢! 尝试下一个片段:

回答 0 投票 0

为什么这个 .xlsx 解析器 javascript 片段在一个目录中有效,但在我的项目中却无效?

我正在努力解决当我想在节点中解析 .xlsx 文件时出现的错误,我希望有人能帮助我。 我的任务是我需要对 SFTP 服务器上的 xlsx 文件做一些事情,并且

回答 0 投票 0

以流的形式读取 .xlsx 文件

我正在使用 xlsx 包 https://www.npmjs.com/package/xlsx 我正在尝试读取一个大小为 50 MB 的 xl 文件,该文件包含 50 列和大约 175,000 条记录。 使用...读取文件花费的时间太长(75 秒)

回答 1 投票 0

使用带有 Powershell 的 Open XML 将自动过滤器设置为 Excel 工作表

我使用 Open XML 2.19 在 powershell 中创建了一个 XLSX 文件。现在我尝试将 AutoFilter 附加到第一行。 在 Microsoft 文档中,工作表具有自动筛选设置。但是我的 $sheet 没有这样的

回答 0 投票 0

npm XLSX.read() 错误:无效的 HTML:找不到<table>

我正在尝试在 ReactJS 应用程序中读取 excel 文件。我已经使用 XLSX 来执行任务。以下是我使用的代码: const readFile = await fetch('../../public/images/Book1....

回答 1 投票 0

csv 文件到 json 保持日期格式不变

我想将 CSV 文件转换为包含相同日期格式的 JSON 数据。 // 这是csv文件的内容 id,name,date,newdate 1,约翰,2022-01-01,01/02/2022 2,玛丽,2022-02-15,02/0...

回答 0 投票 0

你好,谁能帮助我,我想创建一个可以将 excel 文件转换为 pdf 的 javascript 程序

到目前为止,我设法让它成功读取文件,但它只保存了一个带有空白列的pdf。我的 excel 文件包含图像,我只想打印出 A 到 L 列。 到目前为止,我设法让它成功读取文件,但它只保存了一个带有空白列的 pdf。我的 excel 文件包含图像,我只想打印出 A 到 L 列。 <!DOCTYPE html> <html> <head> <title>XLS to PDF Converter</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.4.0/jspdf.umd.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.debug.js"></script> </head> <body> <input type="file" id="fileInput"> <button onclick="convert()">Convert XLS to PDF</button> <script> function convert() { const fileInput = document.getElementById('fileInput'); const file = fileInput.files[0]; const reader = new FileReader(); reader.onload = function() { const arrayBuffer = reader.result; const uint8Array = new Uint8Array(arrayBuffer); // Get the first worksheet from the workbook const workbook = XLSX.read(uint8Array, { type: 'array' }); const worksheet = workbook.Sheets[workbook.SheetNames[0]]; // Create a new PDF document const doc = new jsPDF('p', 'pt', 'a4'); // Set the columns to be printed const columns = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L']; // Set the starting x and y positions let xPos = 40; let yPos = 60; // Loop through the rows and columns and add them to the PDF document for (let i = 1; i <= (worksheet['!rows'] ? worksheet['!rows'].length : 0); i++) { for (let j = 0; j < columns.length; j++) { const cellRef = columns[j] + i.toString(); const cell = worksheet[cellRef]; // Get the cell value and format const value = cell ? cell.v : ''; const format = cell ? cell.z : ''; // Add the cell to the PDF document doc.setFontSize(8); doc.text(xPos, yPos, value.toString(), {align: 'left', baseline: 'middle'}); doc.setFillColor(255, 255, 255); doc.rect(xPos, yPos - 8, 50, 20, 'FD'); doc.line(xPos + 50, yPos - 8, xPos + 50, yPos + 12); doc.line(xPos, yPos - 8, xPos, yPos + 12); doc.line(xPos, yPos + 12, xPos + 50, yPos + 12); // Move to the next column xPos += 50; } // Move to the next row xPos = 40; yPos += 20; } // Save the PDF document doc.save('example.pdf'); }; reader.readAsArrayBuffer(file); } </script> </body> </html> 程序可以读取文件但保存时没有任何内容,格式与excel文件上的单元格格式不一样, 问题似乎出在如何从工作表中检索单元格值。当前的实现只是获取单元格值,而不是单元格的格式或样式。由于未保留格式,因此在呈现 PDF 时可能会导致问题。 要解决此问题,您可以使用 XLSX.utils.sheet_to_json() 方法将工作表转换为 JSON 对象并检索每个单元格的格式和样式信息。 这是您的代码的更新版本,应该处理 Excel 文件中的格式和图像: <!DOCTYPE html> <html> <head> <title>XLS to PDF Converter</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.4.0/jspdf.umd.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.debug.js"></script> </head> <body> <input type="file" id="fileInput"> <button onclick="convert()">Convert XLS to PDF</button> <script> function convert() { const fileInput = document.getElementById('fileInput'); const file = fileInput.files[0]; const reader = new FileReader(); reader.onload = function() { const arrayBuffer = reader.result; const uint8Array = new Uint8Array(arrayBuffer); // Get the first worksheet from the workbook const workbook = XLSX.read(uint8Array, { type: 'array' }); const worksheet = workbook.Sheets[workbook.SheetNames[0]]; // Convert worksheet to JSON object with formatting and style information const json = XLSX.utils.sheet_to_json(worksheet, { header: 1, cellStyles: true, cellHTML: true }); // Create a new PDF document const doc = new jsPDF('p', 'pt', 'a4'); // Set the columns to be printed const columns = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L']; // Set the starting x and y positions let xPos = 40; let yPos = 60; // Loop through the rows and columns and add them to the PDF document for (let i = 0; i < json.length; i++) { const row = json[i]; for (let j = 0; j < columns.length; j++) { const col = columns[j]; const cell = row[j]; // Get the cell value and format const value = cell ? cell : ''; const format = worksheet[col + (i + 1)] ? worksheet[col + (i + 1)].z : ''; // Add the cell to the PDF document doc.setFontSize(8); doc.text(xPos, yPos, value.toString(), { align: 'left', baseline: 'middle' }); doc.setFillColor(255, 255, 255); doc.rect(xPos, yPos - 8, 50, 20, 'FD'); doc.line(xPos + 50, yPos - 8, xPos + 50, yPos + 12); doc.line(xPos, yPos - 8, xPos, yPos + 12); doc.line(xPos, yPos + 12, xPos + 50, yPos + 12); xPos += 50; } // Move to the next row xPos = 40; yPos += 20; } // Save the PDF document doc.save('example.pdf'); }; reader.readAsArrayBuffer(file); } </script> </body> </html>

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.