使用pdftools将R Script pdf转换为excel [英] R Script pdf to excel using pdftools

查看:82
本文介绍了使用pdftools将R Script pdf转换为excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用pdftools将pdf转换为excel.我想提取表值.下面的代码运行完美,但是将所有内容粘贴到行中(我的意思是值不会在不同的列中分开-我唯一想要的就是表,因为它在pdf中(数据和值).有人可以提供代码帮助吗?也许我们需要一个分隔符?我希望获得帮助!以下3张图片:-我得到的Excel输出,预期的Excel输出和正在使用的PDF.

I am using pdftools to convert the pdf to excel. I want to extract the table values.The code below works perfectly but it pastes everything in rows(I mean the values are not separated in different coloumns- The only thing I want is the table as it is in the pdf(the data and values). . Can someone help with the code? Maybe we need a separator? I hope for some help! 3 images below:- Excel output I get,Expected Excel Output and the PDF I am working with.

library(pdftools)
tx<-pdf_text("Path")
tx2<-strsplit(tx,"\n")
library(xlsx)
write.xlsx(tx2,file="ds.xlsx")

推荐答案

尝试一下...

library(pdftools)
library(stringr)
library(xlsx)

tx <- pdf_text("Path")
tx2 <- unlist(str_split(tx, "[\\r\\n]+"))
tx3 <- str_split_fixed(str_trim(tx2), "\\s{2,}", 5)

write.xlsx(tx3, file="ds.xlsx")

这篇关于使用pdftools将R Script pdf转换为excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆