procedure TsSpreadOOXMLReader.ReadDrawing(ANode: TDOMNode;
AWorksheet: TsBasicWorksheet);
var
node, child, child2, child3: TDOMNode;
nodeName: String = '';
rID, fileName, stmp: String;
fromCol, fromRow, toCol, toRow: Integer;
fromColOffs, fromRowOffs, toColOffs, toRowOffs: Double;
data: TEmbeddedObjData;
sheetData: TSheetData;
RotateAngle: Double;
begin
if ANode = nil then
exit;
sheetData := TSheetData(FSheetList[TsWorksheet(AWorksheet).Index]);
ANode := ANode.FirstChild;
while Assigned(ANode) do
begin
nodeName := ANode.NodeName;
fromCol := -1; fromColOffs := 0.0;
fromRow := -1; fromRowOffs := 0.0;
toCol := -1; toColOffs := 0.0;
toRow := -1; toRowOffs := 0.0;
rID := ''; fileName := '';
if nodeName = 'xdr:twoCellAnchor' then
begin
node := ANode.FirstChild;
while Assigned(node) do begin
nodeName := node.NodeName;
if nodeName = 'xdr:from' then
begin
child := node.FirstChild;
while Assigned(child) do begin
nodeName := child.NodeName;
if nodeName = 'xdr:col' then
fromCol := StrToIntDef(GetNodeValue(child), -1)
else if nodeName = 'xdr:row' then
fromRow := StrToIntDef(GetNodeValue(child), -1)
else if nodeName = 'xdr:colOff' then
fromColOffs := EMUToMM(StrToInt64Def(GetNodeValue(child), 0))
else if nodeName = 'xdr:rowOff' then
fromRowOffs := EMUToMM(StrToInt64Def(GetNodeValue(child), 0));
child := child.NextSibling;
end;
end else
if nodeName = 'xdr:to' then
begin
child := node.FirstChild;
while Assigned(child) do begin
nodeName := child.NodeName;
if nodeName = 'xdr:col' then
toCol := StrToIntDef(GetNodeValue(child), -1)
else if nodeName = 'xdr:row' then
toRow := StrToIntDef(GetNodeValue(child), -1)
else if nodeName = 'xdr:colOff' then
toColOffs := EMUToMM(StrToInt64Def(GetNodeValue(child), 0))
else if nodeName = 'xdr:rowOff' then
toRowOffs := EMUToMM(StrToInt64Def(GetNodeValue(child), 0));
child := child.NextSibling;
end;
end else
if nodeName = 'xdr:pic' then
begin
child := node.FirstChild;
while Assigned(child) do begin
nodeName := child.NodeName;
if nodeName = 'xdr:blipFill' then
begin
child2 := child.FirstChild;
while Assigned(child2) do begin
nodeName := child2.NodeName;
if nodeName = 'a:blip' then
rID := GetAttrValue(child2, 'r:embed');
child2 := child2.NextSibling;
end;
end else
if nodeName = 'xdr:nvPicPr' then begin
child2 := child.FirstChild;
while Assigned(child2) do begin
nodeName := child2.NodeName;
if nodeName = 'xdr:cNvPr' then
fileName := GetAttrValue(child2, 'descr');
child2 := child2.NextSibling;
end;
end;
child := child.NextSibling;
end;
end;
node := node.NextSibling;
end;
end;
// oneCellAnchor
if nodeName = 'xdr:oneCellAnchor' then
begin
node := ANode.FirstChild;
while Assigned(node) do begin
nodeName := node.NodeName;
if nodeName = 'xdr:from' then
begin
child := node.FirstChild;
while Assigned(child) do begin
nodeName := child.NodeName;
if nodeName = 'xdr:col' then
fromCol := StrToIntDef(GetNodeValue(child), -1)
else if nodeName = 'xdr:row' then
fromRow := StrToIntDef(GetNodeValue(child), -1)
else if nodeName = 'xdr:colOff' then
fromColOffs := EMUToMM(StrToInt64Def(GetNodeValue(child), 0))
else if nodeName = 'xdr:rowOff' then
fromRowOffs := EMUToMM(StrToInt64Def(GetNodeValue(child), 0));
child := child.NextSibling;
end;
end else
if nodeName = 'xdr:pic' then
begin
child := node.FirstChild;
while Assigned(child) do begin
nodeName := child.NodeName;
if nodeName = 'xdr:blipFill' then
begin
child2 := child.FirstChild;
while Assigned(child2) do begin
nodeName := child2.NodeName;
if nodeName = 'a:blip' then
rID := GetAttrValue(child2, 'r:embed');
child2 := child2.NextSibling;
end;
end else
if nodeName = 'xdr:nvPicPr' then begin
child2 := child.FirstChild;
while Assigned(child2) do begin
nodeName := child2.NodeName;
if nodeName = 'xdr:cNvPr' then
fileName := GetAttrValue(child2, 'descr');
child2 := child2.NextSibling;
end;
end;
if nodeName = 'xdr:spPr' then begin
child2 := child.FirstChild;
while Assigned(child2) do begin
nodeName := child2.NodeName;
if nodeName = 'a:xfrm' then begin
RotateAngle := StrToFloatDef(GetAttrValue(child2, 'rot'),0) / 60000; // Rotation of the image. 60000 is 1 degree
child3 := child2.FirstChild;
while Assigned(child3) do begin
nodeName:=child3.NodeName;
if nodeName = 'a:ext' then begin
toColOffs := EMUToMM(StrToInt64Def(GetAttrValue(child3, 'cx'),0)) + fromColOffs; // cx is the width of the image in EMU's
toRowOffs := EMUToMM(StrToInt64Def(GetAttrValue(child3, 'cy'),0)) + fromRowOffs; // cy is the height of the image in EMU's
end;
child3 := child3.NextSibling;
end;
end;
child2 := child2.NextSibling;
end;
end;
child := child.NextSibling;
end;
end;
node := node.NextSibling;
end;
toCol:=fromCol;
toRow:=fromRow;
end;
if (fromCol <> -1) and (toCol <> -1) and (fromRow <> -1) and (toRow <> -1) and (rID <> '') then
begin
data := TEmbeddedObjData.Create;
data.FromCol := fromCol;
data.FromColOffs := fromColOffs;
data.ToCol := toCol;
data.ToColOffs := toColOffs;
data.FromRow := fromRow;
data.FromRowOffs := fromRowOffs;
data.ToRow := toRow;
data.ToRowOffs := toRowOffs;
data.RelId := rId;
data.FileName := fileName;
data.MediaName := MakeXLPath(sheetData.DrawingRels.FindTarget(rID));
data.ImgIndex := -1;
data.Worksheet := AWorksheet;
data.IsHeaderFooter := false;
FEmbeddedObjList.Add(data);
end;
ANode := ANode.NextSibling;
end;
end;