我正在尝试通过import unittest
class MyTest(unittest.TestCase):
def tearDown(self):
if hasattr(self, '_outcome'): # Python 3.4+
result = self.defaultTestResult() # these 2 methods have no
side effects
self._feedErrorsToResult(result, self._outcome.errors)
else: # Python 3.2 - 3.3 or 3.0 - 3.1 and 2.7
result = getattr(self, '_outcomeForDoCleanups', self._resultForDoCleanups)
error = self.list2reason(result.errors)
failure = self.list2reason(result.failures)
ok = not error and not failure
# demo: report short info immediately (not important)
if not ok:
typ, text = ('ERROR', error) if error else ('FAIL', failure)
msg = [x for x in text.split('\n')[1:] if not x.startswith(' ')] [0]
print("\n%s: %s\n %s" % (typ, self.id(), msg))
def list2reason(self, exc_list):
if exc_list and exc_list[-1][0] is self:
return exc_list[-1][1]
# DEMO tests
def test_success(self):
self.assertEqual(1, 1)
def test_fail(self):
self.assertEqual(2, 1)
def test_error(self):
self.assertEqual(1 / 0, 1)
库合并docx文件。除了Microsoft Word的docx-merger
消息外,其他一切都很好。单击“是”时,它将打开文档,但不会打开输出文件,而是一个缓冲区。
这是我的代码:
"Word found unreadable content in output.docx. Do you want to recover the contents of this document? If you trust the source of this document, click Yes."
我在这里尝试合并const docxMerger = require('docx-merger');
fs.readdir('input/', (err, bufferFiles) => {
var bufferFilesArr = [];
bufferFiles.forEach(bufferFile => {
var file = fs.readFileSync(path.resolve('app/temps/buffer',bufferFile), 'binary');
bufferFilesArr.push(file);
});
var mergedDocx = new docxMerger({}, bufferFilesArr);
mergedDocx.save('nodebuffer', function(data){{
fs.writeFileSync(path.resolve('output','output.docx'), data, 'utf8',function(err){
//callback
});
}});
});
文件夹中的docx
个文件。
它合并了所有这些文件,但是没有此消息我无法打开文件。
答案 0 :(得分:0)
页眉和页脚部分是导致此问题的原因。尝试删除文档中的页眉和页脚部分。