This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
export const blobToFile = (blob: Blob, fileName: string): File => {
|
||||
const file = new File([blob], fileName, {
|
||||
lastModified: new Date().getTime()
|
||||
})
|
||||
return file
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an array of bytes (Uint8Array) to a binary string.
|
||||
* @param {Uint8Array} res - The array of bytes to convert.
|
||||
* @returns {string} The binary string representation of the array of bytes.
|
||||
*/
|
||||
export const byteArrayToBinaryString = (res: Uint8Array): string => {
|
||||
// Create a Uint8Array from the input array (if it's not already)
|
||||
const bytes = new Uint8Array(res)
|
||||
|
||||
// Initialize an empty string to store the binary representation
|
||||
let binary = ''
|
||||
|
||||
// Get the length of the byte array
|
||||
const length = bytes.byteLength
|
||||
|
||||
// Iterate through each byte in the array
|
||||
for (let i = 0; i < length; i++) {
|
||||
// Convert each byte to its binary representation and append to the string
|
||||
binary += String.fromCharCode(bytes[i])
|
||||
}
|
||||
|
||||
// Return the binary string
|
||||
return binary
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
SasStoreService
|
||||
} from '../services'
|
||||
import { getCellAddress, getFinishingCell } from './utils/xl.utils'
|
||||
import { blobToFile, byteArrayToBinaryString } from './utils/file.utils'
|
||||
|
||||
interface XLMapRule {
|
||||
XLMAP_ID: string
|
||||
@@ -141,13 +142,6 @@ export class XLMapComponent implements AfterContentInit, AfterViewInit, OnInit {
|
||||
private sasService: SasService
|
||||
) {}
|
||||
|
||||
private blobToFile(theBlob: Blob, fileName: string): File {
|
||||
const b: any = theBlob
|
||||
b.lastModifiedDate = new Date()
|
||||
b.name = fileName
|
||||
return b as File
|
||||
}
|
||||
|
||||
public xlmapOnClick(xlmap: XLMapListItem) {
|
||||
if (xlmap.id !== this.selectedXLMap?.id) {
|
||||
this.selectedXLMap = xlmap
|
||||
@@ -218,7 +212,7 @@ export class XLMapComponent implements AfterContentInit, AfterViewInit, OnInit {
|
||||
const reader = new FileReader()
|
||||
reader.onload = async (theFile: any) => {
|
||||
/* read workbook */
|
||||
const bstr = this.toBstr(theFile.target.result)
|
||||
const bstr = byteArrayToBinaryString(theFile.target.result)
|
||||
let wb: XLSX.WorkBook | undefined = undefined
|
||||
|
||||
const xlsxOptions: XLSX.ParsingOptions = {
|
||||
@@ -271,16 +265,6 @@ export class XLMapComponent implements AfterContentInit, AfterViewInit, OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
public toBstr(res: any) {
|
||||
const bytes = new Uint8Array(res)
|
||||
let binary = ''
|
||||
const length = bytes.byteLength
|
||||
for (let i = 0; i < length; i++) {
|
||||
binary += String.fromCharCode(bytes[i])
|
||||
}
|
||||
return binary
|
||||
}
|
||||
|
||||
public discardExtractedData() {
|
||||
this.isLoading = false
|
||||
this.isLoadingDesc = ''
|
||||
@@ -330,7 +314,7 @@ export class XLMapComponent implements AfterContentInit, AfterViewInit, OnInit {
|
||||
.join('\n')
|
||||
|
||||
const blob = new Blob([csvContent], { type: 'application/csv' })
|
||||
const file: File = this.blobToFile(blob, this.filename + '.csv')
|
||||
const file: File = blobToFile(blob, this.filename + '.csv')
|
||||
|
||||
filesToUpload.push({
|
||||
file: file,
|
||||
|
||||
Reference in New Issue
Block a user