jt
2021-06-10 5d0d028456874576560552f5a5c4e8b801786f11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using QiHe.CodeLib;
using HH.WMS.Utils.ExcelLibrary.BinaryFileFormat;
using HH.WMS.Utils.ExcelLibrary.BinaryDrawingFormat;
 
namespace HH.WMS.Utils.ExcelLibrary.SpreadSheet
{
    public class Worksheet
    {
        public Workbook Book;
 
        public string Name;
        public SheetType SheetType;
        public MSODRAWING Drawing;
 
        public CellCollection Cells;
 
        internal Worksheet()
        {
        }
 
        public Worksheet(string name)
        {
            this.Name = name;
            this.Cells = new CellCollection();
        }
 
        bool extracted = false;
        Dictionary<Pair<int, int>, Picture> pictures = new Dictionary<Pair<int, int>, Picture>();
        public Dictionary<Pair<int, int>, Picture> Pictures
        {
            get
            {
                if (!extracted)
                {
                    ExtractPictures();
                    extracted = true;
                }
                return pictures;
            }
        }
 
        public Picture ExtractPicture(int row, int col)
        {
            Pair<int, int> pos = new Pair<int, int>(row, col);
            if (Pictures.ContainsKey(pos))
            {
                return Pictures[pos];
            }
            else
            {
                return null;
            }
        }
 
        public void AddPicture(Picture pic)
        {
            pictures[pic.CellPos] = pic;
        }
 
        public void ExtractPictures()
        {           
            if (Drawing != null)
            {
                MsofbtDgContainer dgContainer = Drawing.FindChild<MsofbtDgContainer>();
                if (dgContainer != null)
                {
                    MsofbtSpgrContainer spgrContainer = dgContainer.FindChild<MsofbtSpgrContainer>();
 
                    List<MsofbtSpContainer> spContainers = spgrContainer.FindChildren<MsofbtSpContainer>();
 
                    foreach (MsofbtSpContainer spContainer in spContainers)
                    {
                        MsofbtOPT opt = spContainer.FindChild<MsofbtOPT>();
                        MsofbtClientAnchor anchor = spContainer.FindChild<MsofbtClientAnchor>();
 
                        if (opt != null && anchor != null)
                        {
                            foreach (ShapeProperty prop in opt.Properties)
                            {
                                if (prop.PropertyID == PropertyIDs.BlipId)
                                {
                                    int imageIndex = (int)prop.PropertyValue - 1;
                                    Picture pic = new Picture();
                                    pic.TopLeftCorner.RowIndex = anchor.Row1;
                                    pic.TopLeftCorner.ColIndex = anchor.Col1;
                                    pic.TopLeftCorner.DX = anchor.DX1;
                                    pic.TopLeftCorner.DY = anchor.DY1;
                                    pic.BottomRightCorner.RowIndex = anchor.Row2;
                                    pic.BottomRightCorner.ColIndex = anchor.Col2;
                                    pic.BottomRightCorner.DX = anchor.DX2;
                                    pic.BottomRightCorner.DY = anchor.DY2;
                                    pic.Image = Book.ExtractImage(imageIndex);
                                    pictures[pic.CellPos] = pic;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}