
קדם ‹ Forums ‹ הייטק ‹ Programming Languages ‹ יצירת CSV מxml String בJavaScript
שלום! יש לי String המכיל XmlDocument ואני צריכה לייצר ממנו קובץCsv ולהוריד למחשב. דוקא בקליינט ולא בסרבר. איך עושים זאת?
מצאתי בעצמי תשובה: function downloadCsv(content, fileName, mimeType) { var a = document.createElement('a'); mimeType = mimeType || 'application/octet-stream'; if (navigator.msSaveBlob) { // IE10 navigator.msSaveBlob(new Blob([content], { type: mimeType }), fileName); } else if (URL && 'download' in a) { //html5 A[download] a.href = URL.createObjectURL(new Blob([content], { type: mimeType })); a.setAttribute('download', fileName); document.body.appendChild(a); a.click(); document.body.removeChild(a); } else { location.href = 'data:application/octet-stream,' + encodeURIComponent(content); // only this mime type is supported } } הקריאה לפונקציה היא: downloadCsv(csvContent, 'download.csv', 'text/csv;encoding:utf-8');
Log in to reply.
✨ כדי לשפר את החוויה שלך באתר, אנחנו משתמשים בקבצי עוגיות (Cookies).
האישור שלך יעזור לנו להציג תוכן מותאם אישית, לשפר את השירותים שלנו ולעבוד בצורה חלקה יותר. אפשר תמיד לשנות את ההעדפות שלך בכל שלב.
There was a problem reporting this post.
אנא אשרי שאת רוצה לחסום חבר זה.
לא תוכלי עוד:
אנא המתיני מספר דקות לסיום תהליך זה.
חשוב: לא כל פרסום מאושר, נא לפרט בדיוק במה מדובר
