-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from devlights/add-ExportAsFixedFormat-func
Add Worksheet.ExportAsFixedFormat
- Loading branch information
Showing
6 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,3 +88,5 @@ fabric.properties | |
|
||
# Android studio 3.1+ serialized cache file | ||
.idea/caches/build_file_checksums.ser | ||
|
||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package constants | ||
|
||
type ( | ||
// XlFixedFormatType -- ファイル形式の種類を指定します。 | ||
XlFixedFormatType int | ||
) | ||
|
||
// XlFixedFormatType -- ファイル形式の種類を指定します。 | ||
// | ||
// REFERENCES: | ||
// - https://docs.microsoft.com/ja-jp/office/vba/api/excel.xlfixedformattype | ||
// | ||
//noinspection GoUnusedConst | ||
const ( | ||
XlTypePDF XlFixedFormatType = 0 // PDF | ||
XlTypeXPS XlFixedFormatType = 1 // XPS | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/devlights/goxcel" | ||
"github.com/devlights/goxcel/constants" | ||
) | ||
|
||
// flag parameters | ||
var ( | ||
src string | ||
dst string | ||
) | ||
|
||
// logs | ||
var ( | ||
appLog = log.New(os.Stdout, ">>> ", 0) | ||
) | ||
|
||
func main() { | ||
var ( | ||
returnCode int | ||
) | ||
|
||
if err := run(); err != nil { | ||
_, _ = fmt.Fprint(os.Stderr, err) | ||
returnCode = -1 | ||
} | ||
|
||
appLog.Println("done") | ||
|
||
os.Exit(returnCode) | ||
} | ||
|
||
func run() error { | ||
abs := func(p string) string { | ||
v, _ := filepath.Abs(p) | ||
return v | ||
} | ||
|
||
flag.StringVar(&src, "src", "", "source file") | ||
flag.StringVar(&dst, "dst", "result.pdf", "output pdf name") | ||
flag.Parse() | ||
|
||
if src == "" { | ||
flag.Usage() | ||
return nil | ||
} | ||
|
||
quitFn, _ := goxcel.InitGoxcel() | ||
defer quitFn() | ||
|
||
g, r, _ := goxcel.NewGoxcel() | ||
defer r() | ||
|
||
_ = g.Silent(false) | ||
|
||
wbs, err := g.Workbooks() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
absPath := abs(src) | ||
wb, wbReleaseFn, err := wbs.Open(abs(src)) | ||
if err != nil { | ||
return err | ||
} | ||
defer wbReleaseFn() | ||
appLog.Printf("WorkBook Open: %s", absPath) | ||
|
||
ws, err := wb.Sheets(1) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
absPath = abs(src) | ||
err = ws.ExportAsFixedFormat(constants.XlTypePDF, absPath) | ||
if err != nil { | ||
return err | ||
} | ||
appLog.Printf("Export PDF : %s", absPath) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters