将特定的Excel工作表另存为.csv

编程入门 行业动态 更新时间:2024-10-26 17:36:25
本文介绍了将特定的Excel工作表另存为.csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试弄清楚如何在Linux上通过命令行将特定的Excel工作表另存为CSV.我可以使用以下命令保存第一张纸:

I am trying figure out how to save a specific Excel sheet as CSV via command line on Linux. I am able to save the first sheet with the command below:

libreoffice --headless --convert-to csv --outdir /tmp /tmp/test.xls

似乎应该有一种方法可以指定我要保存的工作表,但我找不到它.

It seems that there should be a way to specify the sheet I want to save, but I am not able to find one.

是否可以通过LibreOffice保存它?

Is there a way to save it via LibreOffice?

推荐答案

命令:

soffice --headless "macro:///Library1.Module1.ConvertSheet(~/Desktop/Software/OpenOffice/examples/input/Test1.ods, Sheet2)"

代码:

Sub ConvertSheet( SpreadSheetPath as String, SheetNameSeek as String) REM IN SpreadSheetPath is the FULL PATH and file REM IN SheetName sheet name to be found and converted to CSV Dim Doc As Object Dim Dummy() SheetNameSeek=trim(SheetNameSeek) If (Not GlobalScope.BasicLibraries.isLibraryLoaded("Tools")) Then GlobalScope.BasicLibraries.LoadLibrary("Tools") End If REM content of an opened window can be replaced with the help of the frame parameter and SearchFlags: SearchFlags = com.sun.star.frame.FrameSearchFlag.CREATE + _ com.sun.star.frame.FrameSearchFlag.ALL REM Set up a propval object to store the filter properties Dim Propval(1) as New com.sun.star.beans.PropertyValue Propval(0).Name = "FilterName" Propval(0).Value = "Text - txt - csv (StarCalc)" Propval(1).Name = "FilterOptions" Propval(1).Value = "44,34,76,1" Url=ConvertToUrl(SpreadSheetPath) Doc = StarDesktop.loadComponentFromURL(Url, "MyFrame", _SearchFlags, Dummy) FileN=FileNameoutofPath(Url) BaseFilename = Tools.Strings.GetFileNameWithoutExtension(FileN) DirLoc=DirectoryNameoutofPath(ConvertFromUrl(Url),"/")+"/" Sheets = Doc.Sheets NumSheets = Sheets.Count - 1 For J = 0 to NumSheets SheetName = Sheets(J).Name if (SheetName = SheetNameSeek) then Doc.getCurrentController.setActiveSheet(Sheets(J)) Filename = DirLoc + BaseFilename + "."+ SheetName + ".csv" FileURL = convertToURL(Filename) Doc.StoreAsURL(FileURL, Propval()) end if Next J Doc.close(true) NextFile = Dir End Sub

更多推荐

将特定的Excel工作表另存为.csv

本文发布于:2023-10-26 11:44:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530038.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:另存为   工作   Excel   csv

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!