1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/exceljs.min-BSCFHLpy.js","assets/index-BBdqDp-U.js","assets/index-CxXbq62u.css","assets/_commonjs-dynamic-modules-BHR_E30J.js"])))=>i.map(i=>d[i]); 2import{a1 as e,r as t,a4 as r,j as s,I as a,B as o,g as l,a2 as n,Z as i,a3 as d,a6 as c}from"./index-BBdqDp-U.js";import{L as h}from"./label-CY3M8m88.js";import{S as u}from"./switch-Cgrk1FjL.js";import{S as p,a as x,b as m,c as f,d as b}from"./select-DfeULGu7.js";import{P as g,M as j,a as v,h as y,d as w}from"./html-to-pdf-CLFU8aMm.js";import{T as $}from"./ToolShell-N0l1Xe1U.js";import{F as k}from"./FileDropzone-D8OacnNZ.js";import"./index-Cdhbpm53.js";import"./index-jVOyRz7F.js";import"./pako.esm-B5ls8mH8.js";import"./ToolPageLayout-Dnhvi4kI.js";import"./circle-x-lLij35gb.js";import"./og-DvtWc_zR.js";import"./chevron-left-JquIZv2x.js";import"./index-agrX3D6K.js";import"./file-detect-6ifzRrkL.js";import"./cloud-upload-yVFJs0s1.js";const C={standard:2,high:2.5,print:3},S={compact:"2px 4px",normal:"4px 7px",roomy:"7px 10px"},N=e=>/\.(xlsx|xlsm)$/i.test(e);async function T(e,t,r={}){const s=e.name.toLowerCase(),a=/\.(csv|tsv|txt|tab)$/i.test(s)||e.type.startsWith("text/"),o=await e.arrayBuffer(),l=new Uint8Array(o);if(a){let e,r="utf-8";l.length>=2&&255===l[0]&&254===l[1]?r="utf-16le":l.length>=2&&254===l[0]&&255===l[1]&&(r="utf-16be");try{e=new TextDecoder(r,{fatal:!1}).decode(l)}catch{e=new TextDecoder("utf-8",{fatal:!1}).decode(l)}if(e=e.replace(/^\uFEFF/,""),!e.trim())throw new Error("This file is empty.");return t.read(e,{type:"string",cellDates:!0})}try{return t.read(l,{type:"array",cellDates:!0,cellNF:!0,...r.sheetsOnly?{bookSheets:!0}:{}})}catch(n){const e=(null==n?void 0:n.message)||"";if(/password|encrypt/i.test(e))throw new Error("This spreadsheet is password-protected. Remove the password in Excel first, then try again.");if(/zip|central directory|corrupt/i.test(e))throw new Error("This file appears to be corrupt. Try re-saving it as .xlsx or .csv.");throw new Error("Couldn't read this spreadsheet. Make sure it's a valid .xlsx, .xls or .csv file.")}}function F(e){if(!e||"string"!=typeof e)return null;const t=/^([0-9A-Fa-f]{6,8})$/.exec(e);if(!t)return null;return"#"+(8===t[1].length?t[1].slice(2):t[1]).toUpperCase()}function E(e){return e?/thick/i.test(e)?"2px solid":/medium/i.test(e)?"1.5px solid":/dashed|dashDot/i.test(e)?"1px dashed":/dotted/i.test(e)?"1px dotted":/double/i.test(e)?"3px double":"1px solid":""}function _(e){let t="";for(;e>0;){const r=(e-1)%26;t=String.fromCharCode(65+r)+t,e=Math.floor((e-1)/26)}return t}function z(e){return e.replace(/[&<>"']/g,e=>({"&":"&","<":"<",">":">",'"':""","'":"'"}[e]))}function P(e){return e.map(e=>{var t;const r=e.font||{},s=[];r.bold&&s.push("font-weight:700"),r.italic&&s.push("font-style:italic"),r.underline&&s.push("text-decoration:underline"),r.strike&&s.push("text-decoration:line-through"),r.size&&s.push(`font-size:${r.size}pt`),r.name&&s.push(`font-family:'${r.name}',Arial,sans-serif`);const a=F(null==(t=r.color)?void 0:t.argb);return a&&s.push(`color:${a}`),`<span style="${s.join(";")}">${z(String(e.text??""))}</span>`}).join("")}const A=({embedded:A}={})=>{const D=e("excel-to-pdf"),[R,O]=t.useState([]),[V,L]=t.useState([]),[M,I]=t.useState({}),[B,H]=t.useState("faithful"),[Z,q]=t.useState("A4"),[W,G]=t.useState("landscape"),[U,Q]=t.useState("narrow"),[J,K]=t.useState(!0),[X,Y]=t.useState(!1),[ee,te]=t.useState(!0),[re,se]=t.useState(!0),[ae,oe]=t.useState(!0),[le,ne]=t.useState("normal"),[ie,de]=t.useState("high"),[ce,he]=t.useState(!0),[ue,pe]=t.useState(""),[xe,me]=t.useState(!1),[fe,be]=t.useState(""),[ge,je]=t.useState(0),ve=R.length>0&&N(R[0].name);t.useEffect(()=>{let e=!1;return(async()=>{if(!R.length)return L([]),void I({});try{const t=await r(()=>import("./xlsx-ByDo_lG2.js"),[]),s=await T(R[0],t,{sheetsOnly:!0});if(e)return;L(s.SheetNames),I(Object.fromEntries(s.SheetNames.map(e=>[e,!0])))}catch{}})(),()=>{e=!0}},[R]);return s.jsx($,{tool:D,embedded:A,children:s.jsxs("div",{className:"max-w-3xl mx-auto space-y-6",children:[s.jsx(k,{files:R,onFilesChange:O,accept:{"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":[".xlsx"],"application/vnd.ms-excel":[".xls"],"application/vnd.ms-excel.sheet.binary.macroenabled.12":[".xlsb"],"text/csv":[".csv"],"text/tab-separated-values":[".tsv"],"text/plain":[".txt",".tab"]},label:"Select a spreadsheet",hint:"Drop an .xlsx, .xls, .xlsb, .csv, .tsv or Unicode-text file here"}),V.length>1&&s.jsxs("div",{className:"bg-card border border-border rounded-lg p-5",children:[s.jsxs(h,{className:"mb-3 block",children:["Sheets to include (",V.filter(e=>!1!==M[e]).length,"/",V.length,")"]}),s.jsx("div",{className:"flex flex-wrap gap-2",children:V.map(e=>{const t=!1!==M[e];return s.jsx("button",{type:"button",onClick:()=>I(r=>({...r,[e]:!t})),className:"px-3 py-1.5 text-xs rounded-full border transition-colors "+(t?"bg-primary text-primary-foreground border-primary":"bg-background text-muted-foreground border-border hover:bg-muted"),children:e},e)})})]}),s.jsxs("div",{className:"bg-card border border-border rounded-lg p-5 space-y-5",children:[s.jsxs("div",{children:[s.jsx(h,{children:"Conversion mode"}),s.jsxs(p,{value:B,onValueChange:e=>H(e),children:[s.jsx(x,{children:s.jsx(m,{})}),s.jsxs(f,{children:[s.jsx(b,{value:"faithful",children:"Faithful â preserve fills, fonts, borders, merged cells (recommended)"}),s.jsx(b,{value:"clean",children:"Clean table â plain formatted grid"})]})]}),s.jsx("p",{className:"text-xs text-muted-foreground mt-1.5",children:ve||0===R.length?"Faithful mode preserves Excel cell colors, fonts, alignment, borders, merged cells, and column widths from .xlsx files.":"Faithful mode requires an .xlsx file â CSV, TSV and .xls will use clean mode automatically."})]}),s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[s.jsxs("div",{children:[s.jsx(h,{children:"Page size"}),s.jsxs(p,{value:Z,onValueChange:e=>q(e),children:[s.jsx(x,{children:s.jsx(m,{})}),s.jsx(f,{children:g.map(e=>s.jsx(b,{value:e,children:e},e))})]})]}),s.jsxs("div",{children:[s.jsx(h,{children:"Orientation"}),s.jsxs(p,{value:W,onValueChange:e=>G(e),children:[s.jsx(x,{children:s.jsx(m,{})}),s.jsxs(f,{children:[s.jsx(b,{value:"landscape",children:"Landscape"}),s.jsx(b,{value:"portrait",children:"Portrait"})]})]})]}),s.jsxs("div",{children:[s.jsx(h,{children:"Margins"}),s.jsxs(p,{value:U,onValueChange:e=>Q(e),children:[s.jsx(x,{children:s.jsx(m,{})}),s.jsx(f,{children:j.map(e=>s.jsx(b,{value:e,className:"capitalize",children:e},e))})]})]})]}),s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[s.jsxs("div",{children:[s.jsx(h,{children:"Cell density"}),s.jsxs(p,{value:le,onValueChange:e=>ne(e),children:[s.jsx(x,{children:s.jsx(m,{})}),s.jsxs(f,{children:[s.jsx(b,{value:"compact",children:"Compact"}),s.jsx(b,{value:"normal",children:"Normal"}),s.jsx(b,{value:"roomy",children:"Roomy"})]})]})]}),s.jsxs("div",{children:[s.jsx(h,{children:"Quality"}),s.jsxs(p,{value:ie,onValueChange:e=>de(e),children:[s.jsx(x,{children:s.jsx(m,{})}),s.jsxs(f,{children:[s.jsx(b,{value:"standard",children:"Standard"}),s.jsx(b,{value:"high",children:"High (recommended)"}),s.jsx(b,{value:"print",children:"Print (300 DPI)"})]})]})]}),s.jsxs("div",{children:[s.jsx(h,{htmlFor:"header",children:"Header text"}),s.jsx(a,{id:"header",value:ue,onChange:e=>pe(e.target.value),placeholder:"Optional"})]})]}),s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[s.jsxs("div",{className:"flex items-center justify-between rounded-md border border-border p-3",children:[s.jsx(h,{htmlFor:"fit",className:"cursor-pointer",children:"Fit table to page width"}),s.jsx(u,{id:"fit",checked:re,onCheckedChange:se})]}),s.jsxs("div",{className:"flex items-center justify-between rounded-md border border-border p-3",children:[s.jsx(h,{htmlFor:"rep",className:"cursor-pointer",children:"Repeat header row"}),s.jsx(u,{id:"rep",checked:ae,onCheckedChange:oe})]}),s.jsxs("div",{className:"flex items-center justify-between rounded-md border border-border p-3",children:[s.jsx(h,{htmlFor:"grid",className:"cursor-pointer",children:"Show gridlines"}),s.jsx(u,{id:"grid",checked:J,onCheckedChange:K})]}),s.jsxs("div",{className:"flex items-center justify-between rounded-md border border-border p-3",children:[s.jsx(h,{htmlFor:"zebra",className:"cursor-pointer",children:"Zebra rows"}),s.jsx(u,{id:"zebra",checked:X,onCheckedChange:Y})]}),s.jsxs("div",{className:"flex items-center justify-between rounded-md border border-border p-3",children:[s.jsx(h,{htmlFor:"titles",className:"cursor-pointer",children:"Print sheet titles"}),s.jsx(u,{id:"titles",checked:ee,onCheckedChange:te})]}),s.jsxs("div",{className:"flex items-center justify-between rounded-md border border-border p-3",children:[s.jsx(h,{htmlFor:"pn",className:"cursor-pointer",children:"Add page numbers"}),s.jsx(u,{id:"pn",checked:ce,onCheckedChange:he})]})]})]}),xe&&s.jsxs("div",{className:"space-y-2",children:[s.jsx(v,{value:ge}),s.jsx("p",{className:"text-sm text-muted-foreground",children:fe})]}),s.jsx("div",{className:"flex items-center justify-end gap-3",children:s.jsxs(o,{size:"lg",onClick:async()=>
2{if(!R.length)return n.error("Select a spreadsheet");const e=R[0];me(!0),i.start(),je(0),i.set(0);const t=e.name.replace(/\.(xlsx?|xlsm|xlsb|csv|tsv|txt|tab)$/i,"")+".pdf",s="faithful"===B&&N(e.name);try{d("excel-to-pdf",t,e.size,[e]);let a="",o=Object.keys(M).filter(e=>!1!==M[e]);if(s){be("Reading workbook (faithful mode)â¦"),i.label("Reading workbook (faithful mode)â¦"),je(15),i.set(.15);const t=e=>!1!==M[e];a=await async function(e,t,s){const a=new(((await r(async()=>{const{default:e}=await import("./exceljs.min-BSCFHLpy.js").then(e=>e.e);return{default:e}},__vite__mapDeps([0,1,2,3]))).default||await r(()=>import("./exceljs.min-BSCFHLpy.js").then(e=>e.e),__vite__mapDeps([0,1,2,3]))).Workbook);await a.xlsx.load(await e.arrayBuffer());const o=[];let l=0;if(a.eachSheet((e,r)=>{var a,n,i,d,c,h,u,p,x,m,f,b,g;if(!t(e.name))return;if("hidden"===e.state||"veryHidden"===e.state)return;if(!e.rowCount||!e.columnCount)return;const j={},v={};((null==(a=e.model)?void 0:a.merges)||Object.keys(e._merges||{})).forEach(e=>{const[t,r]=e.split(":"),s=/^([A-Z]+)(\d+)$/.exec(t),a=/^([A-Z]+)(\d+)$/.exec(r||t);if(!s||!a)return;const o=e=>{let t=0;for(const r of e)t=26*t+(r.charCodeAt(0)-64);return t},l=o(s[1]),n=parseInt(s[2],10),i=o(a[1]),d=parseInt(a[2],10);j[t]={rs:d-n+1,cs:i-l+1};for(let c=n;c<=d;c++)for(let e=l;e<=i;e++){const r=_(e)+c;r!==t&&(v[r]=!0)}});const y=Math.max(1,e.actualColumnCount||e.columnCount||1),w=[];for(let t=1;t<=y;t++){const r=null==(n=e.getColumn(t))?void 0:n.width;r&&!s.fitToWidth?w.push(`<col style="width:${Math.round(7*r)}px">`):w.push("<col>")}const $=Math.max(1,e.actualRowCount||e.rowCount||1),k=[];let C="";for(let t=1;t<=$;t++){const r=e.getRow(t),a=[];for(let e=1;e<=y;e++){const s=_(e)+t;if(v[s])continue;const o=r.getCell(e),l=[],n=o.font||{};n.bold&&l.push("font-weight:700"),n.italic&&l.push("font-style:italic"),n.underline&&l.push("text-decoration:underline"),n.strike&&l.push("text-decoration:line-through"),n.size&&l.push(`font-size:${n.size}pt`),n.name&&l.push(`font-family:'${n.name}',Arial,sans-serif`);const y=F(null==(i=n.color)?void 0:i.argb);y&&l.push(`color:${y}`);const w=o.fill;if(w&&"pattern"===w.type&&"solid"===w.pattern){const e=F(null==(d=w.fgColor)?void 0:d.argb)||F(null==(c=w.bgColor)?void 0:c.argb);e&&l.push(`background:${e}`)}const $=o.alignment||{};$.horizontal?l.push(`text-align:${$.horizontal}`):(["n","d"].includes(o.type)||"number"==typeof o.value)&&l.push("text-align:right"),$.vertical&&l.push("vertical-align:"+("middle"===$.vertical?"middle":"top"===$.vertical?"top":"bottom")),$.wrapText?l.push("white-space:pre-wrap;word-break:break-word"):l.push("white-space:nowrap"),$.indent&&l.push(`padding-left:${8*$.indent+6}px`);const k=o.border;k&&((null==(h=k.top)?void 0:h.style)&&l.push(`border-top:${E(k.top.style)} ${F(null==(u=k.top.color)?void 0:u.argb)||"#8a8a8a"}`),(null==(p=k.right)?void 0:p.style)&&l.push(`border-right:${E(k.right.style)} ${F(null==(x=k.right.color)?void 0:x.argb)||"#8a8a8a"}`),(null==(m=k.bottom)?void 0:m.style)&&l.push(`border-bottom:${E(k.bottom.style)} ${F(null==(f=k.bottom.color)?void 0:f.argb)||"#8a8a8a"}`),(null==(b=k.left)?void 0:b.style)&&l.push(`border-left:${E(k.left.style)} ${F(null==(g=k.left.color)?void 0:g.argb)||"#8a8a8a"}`));let C="";const S=o.value;C=null==S?"":"object"==typeof S&&Array.isArray(S.richText)?P(S.richText):"object"==typeof S&&"text"in S&&"hyperlink"in S?`<a href="${z(String(S.hyperlink))}" style="color:#0563C1;text-decoration:underline">${z(String(S.text))}</a>`:"object"==typeof S&&"formula"in S?z(String(S.result??"")):S instanceof Date?z(S.toLocaleDateString()):z(String("object"==typeof S&&"error"in S?S.error:o.text??S??""));const N=j[s],T=N?` rowspan="${N.rs}" colspan="${N.cs}"`:"";a.push(`<td style="${l.join(";")}"${T}>${C||" "}</td>`)}const o=`<tr${r.height?` style="height:${Math.round(1.33*r.height)}px"`:""}>${a.join("")}</tr>`;1===t&&s.repeatHeader?C=o:k.push(o)}if(!C&&0===k.length)return;l++;const S=s.includeSheetTitles?`<h2 class="sheet-title">${z(e.name)}</h2>`:"",N=o.length>0?'<div class="sheet-break"></div>':"",T=C?`<thead>${C}</thead>`:"";o.push(`${N}<section class="sheet">${S}<table class="xl">${w.join("")}${T}<tbody>${k.join("")}</tbody></table></section>`)}),!l)throw new Error("The selected sheets are empty â nothing to convert.");return o.join("")}(e,t,{includeSheetTitles:ee,repeatHeader:ae,fitToWidth:re,density:le,showGrid:J,zebra:X})}else{be("Loading spreadsheet engineâ¦"),i.label("Loading spreadsheet engineâ¦"),je(6),i.set(.06);const t=await r(()=>import("./xlsx-ByDo_lG2.js"),[]);be("Parsing workbookâ¦"),i.label("Parsing workbookâ¦"),je(18),i.set(.18);const s=await T(e,t);if(!s.SheetNames.length)throw new Error("No sheets found in this file.");const l=s.SheetNames.filter(e=>!1!==M[e]);if(!l.length)throw new Error("Select at least one sheet to export.");o=l;const n=l.reduce((e,t)=>
2e+function(e){const t=e["!ref"];if(!t)return 0;const[,r]=t.split(":");if(!r)return 1;const s=/^([A-Z]+)(\d+)$/.exec(r);if(!s)return 0;let a=0;for(const o of s[1])a=26*a+(o.charCodeAt(0)-64);return a*parseInt(s[2],10)}(s.Sheets[t]),0);if(n>25e4)throw new Error(`This selection contains about ${Math.round(n/1e3)}k cells, too large to render in-browser. Split the workbook or export fewer sheets.`);let d=0;if(a=l.map((e,r)=>{const a=s.Sheets[e];if(!a||!a["!ref"])return"";let o="";try{o=t.utils.sheet_to_html(a,{editable:!1,header:"",footer:""})}catch{return""}const l=o.match(/<table[\s\S]*<\/table>/i);let n=l?l[0]:o;if(!/<t[dh][\s>]/i.test(n))return"";if(ae){let e=!1;n=n.replace(/<table([^>]*)>\s*<tr([^>]*)>([\s\S]*?)<\/tr>/i,(t,r,s,a)=>{e=!0;return`<table${r} class="xl"><thead><tr${s}>${a.replace(/<td/gi,"<th").replace(/<\/td>/gi,"</th>")}</tr></thead><tbody>`}),e&&(n=n.replace(/<\/table>\s*$/i,"</tbody></table>"))}d++;return`${r>0?'<div class="sheet-break"></div>':""}<section class="sheet">${ee?`<h2 class="sheet-title">${z(e)}</h2>`:""}${n}</section>`}).filter(Boolean).join(""),!d)throw new Error("The selected sheets are empty â nothing to convert.")}const l=`\n .sheet{margin:0 0 18px;page-break-inside:auto}\n .sheet-title{font-size:14px;margin:0 0 8px;color:#222;border-bottom:2px solid #999;padding-bottom:4px;font-weight:600;font-family:Arial,sans-serif}\n .sheet-break{page-break-after:always;height:0}\n table.xl{border-collapse:collapse;table-layout:${re?"fixed":"auto"};${re?"width:100%;":""}font-size:10.5px;font-family:Calibri,Arial,sans-serif}\n table.xl td,table.xl th{padding:${S[le]};${J&&!s?"border:1px solid #b8b8b8;":""}vertical-align:top;overflow:hidden}\n ${s&&J?"table.xl td:not([style*='border']){border:1px solid #d5d5d5}":""}\n table.xl thead th{background:#e8ecf1;font-weight:600;color:#1a1a1a}\n ${X?"table.xl tbody tr:nth-child(even) td{background:#fafbfd}":""}\n ${re?"table.xl td,table.xl th{word-break:break-word;overflow-wrap:anywhere}":""}\n `;be("Rendering PDFâ¦"),i.label("Rendering PDFâ¦"),je(35),i.set(.35);const h=await y(a,{pageSize:Z,orientation:W,margin:U,scale:C[ie],imageFormat:"print"===ie?"PNG":"JPEG",jpegQuality:"high"===ie?.94:.88,smartPageBreaks:!0,pageNumbers:ce,headerText:ue,footerText:1===o.length?o[0]:"",title:e.name.replace(/\.(xlsx?|xlsm|xlsb|csv|tsv|txt|tab)$/i,""),subject:"Converted from spreadsheet",fileName:t,preserveStyles:s,extraCss:l,onProgress:(e,t)=>{if(be(e),null!=t){const r=35+Math.round(.6*t);je(r),i.set(r/100,e)}}});w(h,t),c("excel-to-pdf",t,e.size,[e],"success",`${s?"faithful":"clean"}, ${o.length} sheet(s), ${Z} ${W}, ${ie}`),n.success("PDF ready")}catch(a){let r=(null==a?void 0:a.message)??"Failed to convert";/out of memory|allocation/i.test(r)?r="This spreadsheet is too large to convert in the browser. Try exporting fewer sheets or reducing the quality setting.":/network|fetch/i.test(r)&&(r="Couldn't load the converter. Check your connection and try again."),c("excel-to-pdf",t,e.size,[e],"error",r),n.error(r)}finally{i.close(),me(!1),be(""),i.label(""),je(0),i.set(0)}},disabled:xe||!R.length,children:[xe&&s.jsx(l,{className:"w-4 h-4 mr-2 animate-spin"})," Convert to PDF"]})}),s.jsx("p",{className:"text-xs text-muted-foreground text-center",children:"Faithful mode preserves per-cell fills, fonts, colors, borders, alignment, merged cells and column widths from .xlsx files. Charts and images embedded in cells are not yet rendered."})]})})};export{A as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.