Skip to content

Commit

Permalink
Update image
Browse files Browse the repository at this point in the history
  • Loading branch information
pietersv committed Oct 25, 2021
1 parent 4a40cb8 commit a0dedc0
Show file tree
Hide file tree
Showing 18 changed files with 34 additions and 145 deletions.
7 changes: 4 additions & 3 deletions README.md

Large diffs are not rendered by default.

82 changes: 9 additions & 73 deletions lib/msexcel-builder.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/msexcel-builder.js.map

Large diffs are not rendered by default.

78 changes: 18 additions & 60 deletions src/msexcel-builder.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -635,46 +635,6 @@ class Anchor
wb.ele('bookViews').ele('workbookView', {xWindow: '0', yWindow: '90', windowWidth: '19200', windowHeight: '11640'})


class Image
# constructor: (@content, @contentType)
constructor: (@worksheet, @model) ->

@property 'model', {
get: () ->
switch (@type)
when 'background' then return {type: @type, imageId: @imageId}
when 'image' then return{
type: @type,
imageId: @imageId,
hyperlinks: @range.hyperlinks,
range: {
tl: @range.tl.model,
br: @range.br && @range.br.model,
ext: @range.ext,
editAs: @range.editAs,
}
}
else throw new Error('Invalid Image Type')
set: (model) ->
@type = model.type;
@imageId = model.imageId;

if model.type == 'image'
if typeof model.range == 'string'
decoded = colCache.decode(model.range)
@range = {
tl: new Anchor(@worksheet, {col: decoded.left, row: decoded.top}, -1),
br: new Anchor(@worksheet, {col: decoded.right, row: decoded.bottom}, 0),
editAs: 'oneCell',
}
else @range = {
tl: new Anchor(@worksheet, model.range.tl, 0),
br: model.range.br && new Anchor(@worksheet, model.range.br, 0),
ext: model.range.ext,
editAs: model.range.editAs,
hyperlinks: model.hyperlinks || model.range.hyperlinks,
}
}

class Sheet
constructor: (@book, @name, @cols, @rows) ->
Expand Down Expand Up @@ -714,10 +674,8 @@ class Sheet
editAs: 'oneCell',
}

## tries to uncompress base64

id = @book.medias.length + 1
imageToAdd = new Image(id, image.extension, image.base64, @range)
imageToAdd = new Image(id, image.extension, image.base64, @range, image.options||{})
media = @book._addMediaFromImage(imageToAdd)
# drawingId = @book._addDrawingFromImage(imageToAdd)
# wsDwRelId = @sheet._addDrawingFromImage(imageToAdd)
Expand Down Expand Up @@ -1281,23 +1239,23 @@ class Style
return ss.end({pretty: false})

class Image
constructor: (@id, @extension, @content, @range) ->
constructor: (@id, @extension, @content, @range, @options) ->
@editAs = 'oneCell'


publish: (sheet, zip, media)->
## Inject image, it's used by sheet
## 1. write data to media folder
## convert base 64 to text
## define filename based on number of existing medias
## writes to media
##
## 2. create reference for media to drawing
## 3. create the actual drawing using reference for media and set location
## 4. creates reference for drawing to sheet.
## 5. use image rel to sheet.

toDrawingXml: (relId,type)->
## Inject image, it's used by sheet
## 1. write data to media folder
## convert base 64 to text
## define filename based on number of existing medias
## writes to media
##
## 2. create reference for media to drawing
## 3. create the actual drawing using reference for media and set location
## 4. creates reference for drawing to sheet.
## 5. use image rel to sheet.

toDrawingXml: (relId,spec)->
# pngVersionRel = 'rId1'
# svgVersionRel = 'rId2'

Expand Down Expand Up @@ -1357,7 +1315,7 @@ class Image
, 'val': 0
})

if type =='svg'
if @extension =='svg'
ext = extLst.ele('a:ext', {
'uri': '{96DAC541-7B7A-43D3-8B79-37D633B846F1}'
})
Expand All @@ -1367,15 +1325,15 @@ class Image
})


blipFill.ele('a:stretch')
if @options.stretch
blipFill.ele('a:stretch')
blipFill.ele('srcRect')
#.ele('a:fillRect')
spPr = pic.ele('xdr:spPr')
xfrm = spPr.ele('a:xfrm')
xfrm.ele('a:off', {'x': 609600, 'y': 190500})
xfrm.ele('a:ext', {'cx': 2857500, 'cy': 2857500})
spPr.ele('a:prstGeom', {'prst': 'rect'}).ele('a:avLst')

twoCellAnchor.ele('xdr:clientData')
dr.end({pretty: false})

Expand Down Expand Up @@ -1481,7 +1439,7 @@ class Workbook
# - build xl/drawings/drawing(1-N).xml
drawingFilename = wbMediaCounter + '.xml'
sheet.wsRels.push({id: relId, target: '../drawings/drawing' + drawingFilename})
zip.file('xl/drawings/drawing' + drawingFilename, image.toDrawingXml(relId, image.type))
zip.file('xl/drawings/drawing' + drawingFilename, image.toDrawingXml(relId, image))

# - build xl/drawings/_rels/drawing(1-N).xml.rels
zip.file('xl/drawings/_rels/drawing' + wbMediaCounter + '.xml.rels', new XlDrawingRels(dwRels).toxml())
Expand Down
Empty file added test/.Rhistory
Empty file.
10 changes: 2 additions & 8 deletions test/image-png.js

Large diffs are not rendered by default.

Binary file modified test/out/autofilter.xlsx
Binary file not shown.
Binary file modified test/out/borders.xlsx
Binary file not shown.
Binary file modified test/out/example-1.xlsx
Binary file not shown.
Binary file modified test/out/example.xlsx
Binary file not shown.
Binary file modified test/out/example2.xlsx
Binary file not shown.
Binary file modified test/out/example3.xlsx
Binary file not shown.
Binary file modified test/out/formula.xlsx
Binary file not shown.
Binary file modified test/out/freeze.xlsx
Binary file not shown.
Binary file modified test/out/numberformat.xlsx
Binary file not shown.
Binary file modified test/out/print.xlsx
Binary file not shown.
Binary file modified test/out/style.xlsx
Binary file not shown.
Binary file modified test/out/style2.xlsx
Binary file not shown.

0 comments on commit a0dedc0

Please sign in to comment.