Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
leaf-hlcm
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hlcm
leaf-hlcm
Commits
412e3c8b
Commit
412e3c8b
authored
Jan 06, 2023
by
王炜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
excel转换为pdf,并调整行列
parent
97136093
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
6 deletions
+15
-6
WordToPdf.java
src/main/java/leaf/plugin/word2pdf/WordToPdf.java
+15
-6
No files found.
src/main/java/leaf/plugin/word2pdf/WordToPdf.java
View file @
412e3c8b
...
...
@@ -107,9 +107,11 @@ public class WordToPdf {
*
* @param inFilePath
* @param outFilePath
* @param fitToPagesTall 所有行为一页
* @param fitToPagesWide 所有列为一页
* @return
*/
public
static
boolean
excel2pdf
(
String
inFilePath
,
String
outFilePath
)
{
public
static
boolean
excel2pdf
(
String
inFilePath
,
String
outFilePath
,
Object
fitToPagesTall
,
Object
fitToPagesWide
)
{
ActiveXComponent
activeXComponent
=
new
ActiveXComponent
(
"Excel.Application"
);
activeXComponent
.
setProperty
(
"Visible"
,
false
);
...
...
@@ -117,6 +119,13 @@ public class WordToPdf {
Dispatch
excels
=
activeXComponent
.
getProperty
(
"Workbooks"
).
toDispatch
();
Dispatch
excel
=
Dispatch
.
call
(
excels
,
"Open"
,
inFilePath
,
false
,
true
).
toDispatch
();
Dispatch
currentSheet
=
Dispatch
.
get
((
Dispatch
)
excel
,
"ActiveSheet"
).
toDispatch
();
Dispatch
pageSetup
=
Dispatch
.
get
(
currentSheet
,
"PageSetup"
)
.
toDispatch
();
//Dispatch.put(pageSetup, "Zoom", 50);
Dispatch
.
put
(
pageSetup
,
"FitToPagesTall"
,
fitToPagesTall
);
Dispatch
.
put
(
pageSetup
,
"FitToPagesWide"
,
fitToPagesWide
);
Dispatch
.
call
(
excel
,
"ExportAsFixedFormat"
,
0
,
outFilePath
);
Dispatch
.
call
(
excel
,
"Close"
,
false
);
activeXComponent
.
invoke
(
"Quit"
);
...
...
@@ -144,6 +153,7 @@ public class WordToPdf {
Dispatch
pageSetup
=
Dispatch
.
get
(
currentSheet
,
"PageSetup"
)
.
toDispatch
();
Dispatch
.
put
(
pageSetup
,
"Orientation"
,
new
Variant
(
2
));
//设置缩放,值为100或false
Dispatch
.
call
(
excel
,
"ExportAsFixedFormat"
,
0
,
outFilePath
);
Dispatch
.
call
(
excel
,
"Close"
,
false
);
...
...
@@ -175,14 +185,13 @@ public class WordToPdf {
public
static
void
main
(
String
[]
args
)
throws
Exception
{
// String jacobDllPath = "D:\\ideaProjects\\leaf-hlcm\\src\\main\\webapp\\WEB-INF\\server-script\\jacob\\jacob-1.18
-x64.dll";
//
System.setProperty("jacob.dll.path", jacobDllPath);
//
System.setProperty("com.jacob.debug", "true");
String
jacobDllPath
=
"E:\\idea_workspace\\leaf-hlcm\\src\\main\\webapp\\WEB-INF\\server-script\\jacob\\jacob-1.19
-x64.dll"
;
System
.
setProperty
(
"jacob.dll.path"
,
jacobDllPath
);
System
.
setProperty
(
"com.jacob.debug"
,
"true"
);
// word2pdf("D:\\u01\\hls_file\\excel\\8F5D12B0B1504518928FDD193C67A0A5con28168",
// "D:\\hand-Prpjects\\融资租赁合同文本-4pdf.pdf");
// cutPdf("D:\\\\hand-Prpjects\\\\付款请求书打印.pdf");
// excel2pdf("D:\\work\\leafProjects\\YondaTl\\src\\test.xlsx",
// "D:\\work\\leafProjects\\YondaTl\\src\\付款通知书NEW.pdf");
excel2pdf
(
"C:\\Users\\Administrator\\Desktop\\对账单(白云BJJ22120045).xlsx"
,
"C:\\Users\\Administrator\\Desktop\\c.pdf"
,
1
,
1
);
// excel2pdfOrientation("D:\\work\\leafProjects\\YondaTl\\src\\test.xlsx",
// "D:\\work\\leafProjects\\YondaTl\\src\\付款通知书NEW.pdf");
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment