w-html2docx 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/w-html2docx.umd.js +1 -1
- package/docs/WHtml2docx.mjs.html +1 -1
- package/docs/global.html +1 -1
- package/docs/index.html +1 -1
- package/package.json +1 -1
- package/srcPython/htmlToDocx.py +83 -27
- package/test/ztmp.html +57 -5
- package/test/ztmpTrue.docx +0 -0
package/dist/w-html2docx.umd.js
CHANGED
package/docs/WHtml2docx.mjs.html
CHANGED
|
@@ -246,7 +246,7 @@ export default WHtml2docx
|
|
|
246
246
|
<br class="clear">
|
|
247
247
|
|
|
248
248
|
<footer>
|
|
249
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on
|
|
249
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Mon Nov 24 2025 21:19:24 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
250
250
|
</footer>
|
|
251
251
|
|
|
252
252
|
<script>prettyPrint();</script>
|
package/docs/global.html
CHANGED
|
@@ -593,7 +593,7 @@
|
|
|
593
593
|
<br class="clear">
|
|
594
594
|
|
|
595
595
|
<footer>
|
|
596
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on
|
|
596
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Mon Nov 24 2025 21:19:24 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
597
597
|
</footer>
|
|
598
598
|
|
|
599
599
|
<script>prettyPrint();</script>
|
package/docs/index.html
CHANGED
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
<br class="clear">
|
|
72
72
|
|
|
73
73
|
<footer>
|
|
74
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on
|
|
74
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Mon Nov 24 2025 21:19:24 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
75
75
|
</footer>
|
|
76
76
|
|
|
77
77
|
<script>prettyPrint();</script>
|
package/package.json
CHANGED
package/srcPython/htmlToDocx.py
CHANGED
|
@@ -86,7 +86,7 @@ def htmlToDocx(fpInSrc, fpInTemp, fpOut, opt):
|
|
|
86
86
|
app = wc.Dispatch('Word.Application')
|
|
87
87
|
|
|
88
88
|
#正式版須隱藏
|
|
89
|
-
app.Visible = False
|
|
89
|
+
app.Visible = False
|
|
90
90
|
|
|
91
91
|
#不詢問使用者
|
|
92
92
|
app.DisplayAlerts = False
|
|
@@ -95,32 +95,42 @@ def htmlToDocx(fpInSrc, fpInTemp, fpOut, opt):
|
|
|
95
95
|
docInTemp = app.Documents.Open(fpInTemp)
|
|
96
96
|
docInSrc = app.Documents.Open(fpInSrc)
|
|
97
97
|
|
|
98
|
-
|
|
99
|
-
docInSrc.
|
|
100
|
-
app.Selection.WholeStory()
|
|
101
|
-
app.Selection.Copy()
|
|
98
|
+
# 取得來源文件全文 Range(含格式)
|
|
99
|
+
rngSrc = docInSrc.Range()
|
|
102
100
|
|
|
103
|
-
|
|
104
|
-
docInTemp.
|
|
105
|
-
|
|
106
|
-
#
|
|
107
|
-
#
|
|
101
|
+
# 取得模板文件的主內容 Range
|
|
102
|
+
rngDst = docInTemp.Content # 或 docInTemp.Range()
|
|
103
|
+
|
|
104
|
+
# 如果你想插在文件最後,可先收合到結尾
|
|
105
|
+
WdCollapseEnd = 0 #wdCollapseEnd, 收合到Range結尾
|
|
106
|
+
rngDst.Collapse(WdCollapseEnd)
|
|
107
|
+
|
|
108
|
+
# 直接複製格式化文字(等同貼上,但不經過剪貼簿也不靠 Selection)
|
|
109
|
+
rngDst.FormattedText = rngSrc.FormattedText
|
|
110
|
+
|
|
111
|
+
# #選擇src並複製全文
|
|
112
|
+
# docInSrc.Activate()
|
|
113
|
+
# app.Selection.WholeStory()
|
|
114
|
+
# app.Selection.Copy()
|
|
115
|
+
|
|
116
|
+
# #選擇模板並貼上全文
|
|
117
|
+
# docInTemp.Activate()
|
|
118
|
+
# app.Selection.Paste()
|
|
119
|
+
# # WdFormatOriginalFormatting = 16
|
|
120
|
+
# # app.Selection.PasteAndFormat(WdFormatOriginalFormatting)
|
|
108
121
|
|
|
109
122
|
#選擇模板調整字型
|
|
110
123
|
try:
|
|
111
124
|
|
|
112
125
|
fontFamilies=opt['fontFamilies']
|
|
113
126
|
|
|
114
|
-
if
|
|
115
|
-
|
|
116
|
-
#print(fontFamilies)
|
|
127
|
+
if isinstance(fontFamilies, (list, tuple)) and len(fontFamilies) > 0:
|
|
128
|
+
#print(fontFamilies)
|
|
117
129
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
# print(fn)
|
|
123
|
-
app.Selection.Font.Name = fn
|
|
130
|
+
rng = docInTemp.Range()
|
|
131
|
+
for fn in fontFamilies:
|
|
132
|
+
# print(fn)
|
|
133
|
+
rng.Font.Name = fn
|
|
124
134
|
|
|
125
135
|
except:
|
|
126
136
|
err=getError()
|
|
@@ -146,10 +156,8 @@ def htmlToDocx(fpInSrc, fpInTemp, fpOut, opt):
|
|
|
146
156
|
maxH = (pageH - topM - bottomM) * 0.937043054427296 #高度須預留圖名空間
|
|
147
157
|
maxH = maxH * imgRatioHeightMax
|
|
148
158
|
|
|
149
|
-
docInTemp.
|
|
150
|
-
|
|
151
|
-
#print(len(app.Selection.Range.InlineShapes)) #有幾張圖
|
|
152
|
-
for s in app.Selection.Range.InlineShapes:
|
|
159
|
+
# 使用 docInTemp.InlineShapes 直接取得整份文件所有圖片
|
|
160
|
+
for s in docInTemp.InlineShapes:
|
|
153
161
|
try:
|
|
154
162
|
|
|
155
163
|
#w, h
|
|
@@ -166,19 +174,67 @@ def htmlToDocx(fpInSrc, fpInTemp, fpOut, opt):
|
|
|
166
174
|
s.Width = w * scale #只設width, LockAspectRatio=true會讓height依比例調整
|
|
167
175
|
|
|
168
176
|
except:
|
|
169
|
-
|
|
170
|
-
|
|
177
|
+
pass
|
|
178
|
+
|
|
179
|
+
except:
|
|
180
|
+
err=getError()
|
|
181
|
+
print(err)
|
|
182
|
+
|
|
183
|
+
#設定前後行距
|
|
184
|
+
try:
|
|
185
|
+
|
|
186
|
+
for p in docInTemp.Paragraphs:
|
|
187
|
+
|
|
188
|
+
try:
|
|
189
|
+
lf = p.Range.ListFormat
|
|
190
|
+
except:
|
|
191
|
+
#若可能沒有ListFormat須跳過
|
|
192
|
+
continue
|
|
193
|
+
|
|
194
|
+
listType = lf.ListType # 0,1,2,3,4
|
|
195
|
+
listStr = lf.ListString # '•', '1.', ''...
|
|
196
|
+
|
|
197
|
+
# #測試顯示ListType
|
|
198
|
+
# try:
|
|
199
|
+
# rng = p.Range.Duplicate
|
|
200
|
+
# rng.End = rng.End - 1 #最末是換行符號, 不能插在換行符號後面
|
|
201
|
+
# rng.InsertAfter(f"[{listType},{listStr}]")
|
|
202
|
+
# except:
|
|
203
|
+
# err = getError()
|
|
204
|
+
# print(err)
|
|
205
|
+
|
|
206
|
+
WdListNoNumbering = 0 #普通段落
|
|
207
|
+
WdListSingleLevelNumber = 1 #單層編號清單
|
|
208
|
+
WdListMultiLevel = 2 #多層編號清單
|
|
209
|
+
WdListBullet = 3 #項目符號清單
|
|
210
|
+
WdListOutlineNumbering = 4 #大綱編號
|
|
211
|
+
is_list = (listType != WdListNoNumbering) or (listStr != "")
|
|
212
|
+
|
|
213
|
+
if is_list:
|
|
214
|
+
|
|
215
|
+
fmt = p.Format
|
|
216
|
+
|
|
217
|
+
#關閉自動段前段後距離
|
|
218
|
+
try:
|
|
219
|
+
fmt.SpaceBeforeAuto = False
|
|
220
|
+
fmt.SpaceAfterAuto = False
|
|
221
|
+
except:
|
|
222
|
+
pass
|
|
223
|
+
|
|
224
|
+
# 設定為 0.5 行
|
|
225
|
+
fmt.LineUnitBefore = 0.5
|
|
226
|
+
fmt.LineUnitAfter = 0.5
|
|
171
227
|
|
|
172
228
|
except:
|
|
173
229
|
err=getError()
|
|
174
230
|
print(err)
|
|
175
231
|
|
|
176
232
|
#SaveAs
|
|
177
|
-
WdSaveFormat = 16 #
|
|
233
|
+
WdSaveFormat = 16 #wdFormatDocumentDefault=16(docx) #https://learn.microsoft.com/zh-tw/office/vba/api/word.wdsaveformat
|
|
178
234
|
docInTemp.SaveAs2(fpOut, WdSaveFormat)
|
|
179
235
|
|
|
180
236
|
# Close
|
|
181
|
-
WdDoNotSaveChanges = 0
|
|
237
|
+
WdDoNotSaveChanges = 0 #wdDoNotSaveChanges
|
|
182
238
|
docInTemp.Close(WdDoNotSaveChanges)
|
|
183
239
|
docInSrc.Close(WdDoNotSaveChanges)
|
|
184
240
|
|
package/test/ztmp.html
CHANGED
|
@@ -217,30 +217,82 @@
|
|
|
217
217
|
</ul>
|
|
218
218
|
<hr>
|
|
219
219
|
<h2>三、工作項目與進度</h2>
|
|
220
|
-
|
|
220
|
+
|
|
221
|
+
<p>測試無序巢狀清單</p>
|
|
222
|
+
<ul>
|
|
223
|
+
<li style="margin:7px 0;"><p><strong>資料前處理</strong></p>
|
|
221
224
|
<ul>
|
|
222
|
-
<li style="margin:7px 0;"><strong>資料前處理</strong><ul>
|
|
223
225
|
<li style="margin:7px 0;">格式轉換</li>
|
|
224
226
|
<li style="margin:7px 0;">欄位標準化</li>
|
|
225
227
|
<li style="margin:7px 0;">雜訊清理</li>
|
|
226
228
|
</ul>
|
|
227
229
|
</li>
|
|
228
|
-
<li style="margin:7px 0;"><strong>資料分析模組</strong
|
|
230
|
+
<li style="margin:7px 0;"><p><strong>資料分析模組</strong></p>
|
|
231
|
+
<ul>
|
|
229
232
|
<li style="margin:7px 0;">統計分析</li>
|
|
230
|
-
<li style="margin:7px 0;"
|
|
233
|
+
<li style="margin:7px 0;">時間序列模型<ul>
|
|
231
234
|
<li style="margin:7px 0;">ARIMA</li>
|
|
232
235
|
<li style="margin:7px 0;">Prophet</li>
|
|
233
236
|
</ul>
|
|
234
237
|
</li>
|
|
235
238
|
</ul>
|
|
236
239
|
</li>
|
|
237
|
-
<li style="margin:7px 0;"><strong>視覺化平台</strong
|
|
240
|
+
<li style="margin:7px 0;"><p><strong>視覺化平台</strong></p>
|
|
241
|
+
<ul>
|
|
238
242
|
<li style="margin:7px 0;">儀表板建立</li>
|
|
239
243
|
<li style="margin:7px 0;">自訂圖層呈現</li>
|
|
240
244
|
</ul>
|
|
241
245
|
</li>
|
|
246
|
+
<li style="margin:7px 0;"><p><strong>資料流程自動化</strong>:各自獨立運行,且兼顧完整性與流程自動化之執行方式。</p>
|
|
247
|
+
</li>
|
|
248
|
+
<li style="margin:7px 0;"><p><strong>使用者介面改善</strong>:通過多人協作與回饋等方式,協助使用者介面改善。</p>
|
|
249
|
+
</li>
|
|
250
|
+
<li style="margin:7px 0;"><p><strong>統計分析</strong></p>
|
|
251
|
+
<p> 須說明統計分析之數學模型,以及輸出入之資料格式。</p>
|
|
252
|
+
</li>
|
|
253
|
+
<li style="margin:7px 0;"><p><strong>時間序列模型</strong></p>
|
|
254
|
+
<p> 須說明所採用之時間序列模型,包含數學基礎、演算法與回測之統計分析結果。</p>
|
|
255
|
+
</li>
|
|
256
|
+
</ul>
|
|
257
|
+
<p>測試有序巢狀清單</p>
|
|
258
|
+
<ol>
|
|
259
|
+
<li style="margin:7px 0;"><p><strong>資料前處理</strong></p>
|
|
260
|
+
<ul>
|
|
261
|
+
<li style="margin:7px 0;">格式轉換</li>
|
|
262
|
+
<li style="margin:7px 0;">欄位標準化</li>
|
|
263
|
+
<li style="margin:7px 0;">雜訊清理</li>
|
|
242
264
|
</ul>
|
|
265
|
+
</li>
|
|
266
|
+
<li style="margin:7px 0;"><p><strong>資料分析模組</strong></p>
|
|
267
|
+
<ul>
|
|
268
|
+
<li style="margin:7px 0;">統計分析</li>
|
|
269
|
+
<li style="margin:7px 0;">時間序列模型<ul>
|
|
270
|
+
<li style="margin:7px 0;">ARIMA</li>
|
|
271
|
+
<li style="margin:7px 0;">Prophet</li>
|
|
272
|
+
</ul>
|
|
273
|
+
</li>
|
|
274
|
+
</ul>
|
|
275
|
+
</li>
|
|
276
|
+
<li style="margin:7px 0;"><p><strong>視覺化平台</strong></p>
|
|
277
|
+
<ul>
|
|
278
|
+
<li style="margin:7px 0;">儀表板建立</li>
|
|
279
|
+
<li style="margin:7px 0;">自訂圖層呈現</li>
|
|
280
|
+
</ul>
|
|
281
|
+
</li>
|
|
282
|
+
<li style="margin:7px 0;"><p><strong>資料流程自動化</strong>:各自獨立運行,且兼顧完整性與流程自動化之執行方式。</p>
|
|
283
|
+
</li>
|
|
284
|
+
<li style="margin:7px 0;"><p><strong>使用者介面改善</strong>:通過多人協作與回饋等方式,協助使用者介面改善。</p>
|
|
285
|
+
</li>
|
|
286
|
+
<li style="margin:7px 0;"><p><strong>統計分析</strong></p>
|
|
287
|
+
<p> 須說明統計分析之數學模型,以及輸出入之資料格式。</p>
|
|
288
|
+
</li>
|
|
289
|
+
<li style="margin:7px 0;"><p><strong>時間序列模型</strong></p>
|
|
290
|
+
<p> 須說明所採用之時間序列模型,包含數學基礎、演算法與回測之統計分析結果。</p>
|
|
291
|
+
</li>
|
|
292
|
+
</ol>
|
|
293
|
+
|
|
243
294
|
<hr>
|
|
295
|
+
|
|
244
296
|
<h2>四、成果內容</h2>
|
|
245
297
|
<h3>4.1 表格測試</h3>
|
|
246
298
|
<table>
|
package/test/ztmpTrue.docx
CHANGED
|
Binary file
|