GetTables provides the method to get all tables in a worksheet by given worksheet name.
(sheet string)
| 127 | // GetTables provides the method to get all tables in a worksheet by given |
| 128 | // worksheet name. |
| 129 | func (f *File) GetTables(sheet string) ([]Table, error) { |
| 130 | var tables []Table |
| 131 | ws, err := f.workSheetReader(sheet) |
| 132 | if err != nil { |
| 133 | return tables, err |
| 134 | } |
| 135 | if ws.TableParts == nil { |
| 136 | return tables, err |
| 137 | } |
| 138 | for _, tbl := range ws.TableParts.TableParts { |
| 139 | if tbl != nil { |
| 140 | target := f.getSheetRelationshipsTargetByID(sheet, tbl.RID) |
| 141 | tableXML := strings.ReplaceAll(target, "..", "xl") |
| 142 | content, ok := f.Pkg.Load(tableXML) |
| 143 | if !ok { |
| 144 | continue |
| 145 | } |
| 146 | var t xlsxTable |
| 147 | if err := f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(content.([]byte)))). |
| 148 | Decode(&t); err != nil && err != io.EOF { |
| 149 | return tables, err |
| 150 | } |
| 151 | table := Table{ |
| 152 | rID: tbl.RID, |
| 153 | tID: t.ID, |
| 154 | tableXML: tableXML, |
| 155 | Range: t.Ref, |
| 156 | Name: t.Name, |
| 157 | } |
| 158 | if t.TableStyleInfo != nil { |
| 159 | table.StyleName = t.TableStyleInfo.Name |
| 160 | table.ShowColumnStripes = t.TableStyleInfo.ShowColumnStripes |
| 161 | table.ShowFirstColumn = t.TableStyleInfo.ShowFirstColumn |
| 162 | table.ShowLastColumn = t.TableStyleInfo.ShowLastColumn |
| 163 | table.ShowRowStripes = &t.TableStyleInfo.ShowRowStripes |
| 164 | } |
| 165 | tables = append(tables, table) |
| 166 | } |
| 167 | } |
| 168 | return tables, err |
| 169 | } |
| 170 | |
| 171 | // DeleteTable provides the method to delete table by given table name. |
| 172 | func (f *File) DeleteTable(name string) error { |