| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- const AdmZip = require('adm-zip');
- const zip = new AdmZip('C:\\Users\\15850\\Downloads\\DOP生产管理用户操作手册.docx');
- // Read styles.xml to understand style definitions
- const stylesXml = zip.readAsText('word/styles.xml');
- const styleIds = [];
- const styleIdRegex = /<w:style[^>]*w:styleId="([^"]+)"[^>]*>/g;
- let sm;
- while ((sm = styleIdRegex.exec(stylesXml)) !== null) {
- styleIds.push(sm[1]);
- }
- console.log('=== Style IDs ===');
- console.log(styleIds.join(', '));
- // Read document.xml
- const xml = zip.readAsText('word/document.xml');
- // Extract all text
- const allText = [];
- const textRegex = /<w:t[^>]*>([^<]*)<\/w:t>/g;
- let tm;
- while ((tm = textRegex.exec(xml)) !== null) {
- if (tm[1].trim()) allText.push(tm[1]);
- }
- console.log('\n=== All text (first 150) ===');
- console.log(allText.slice(0, 150).join(' | '));
- console.log('\n=== All text (total ' + allText.length + ' segments) ===');
- console.log(allText.join('\n'));
- // Find paragraph styles used
- const paraStyles = [];
- const pStyleRegex = /<w:pStyle w:val="([^"]+)"/g;
- let pm;
- while ((pm = pStyleRegex.exec(xml)) !== null) {
- paraStyles.push(pm[1]);
- }
- console.log('\n=== Paragraph styles used ===');
- console.log([...new Set(paraStyles)].join(', '));
- // Count tables
- const tableCount = (xml.match(/<w:tbl>/g) || []).length;
- console.log('\n=== Table count: ' + tableCount + ' ===');
- // Count images
- const imageCount = (xml.match(/<w:drawing>/g) || []).length;
- console.log('=== Image count: ' + imageCount + ' ===');
|