Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This is common part for sheet relations #1

Open
hohlick opened this issue Aug 15, 2017 · 0 comments
Open

This is common part for sheet relations #1

hohlick opened this issue Aug 15, 2017 · 0 comments
Assignees

Comments

@hohlick
Copy link
Owner

hohlick commented Aug 15, 2017

Source = Excel.Workbook(File.Contents(FullPath), false, true),
// leave sheets only
FilteredSheets = Table.SelectRows(Source, each ([Kind] = "Sheet")),
// sheets in PQ initially in appearance order, i.e. sheets index (despite visibility)
AddSheetsIndex = Table.AddIndexColumn(FilteredSheets, "Index", 1, 1),
// check SheetNames parameter
SheetNames = if SheetNames is text then {SheetNames} else if SheetNames is list then SheetNames else null,
// filter sheets by name if provided
FilteredByNames = if SheetNames = null or List.IsEmpty(SheetNames) then AddSheetsIndex else Table.SelectRows(AddSheetsIndex, each List.Contains(SheetNames, [Name])),
// UnZip file
UnZipped = Table.Buffer(fnUnZip(File.Contents(FullPath))),
/*
let
Source = Folder.Files(Folder),
file = Source{[Name = FileName, Folder Path = Folder & "\"]}[Content],
UnZippedFile = Table.Buffer(fnUnZip(file))
in
Table.Buffer(UnZippedFile),
*/
// relations id table for sheets
workbook =
let
Source = UnZipped,
Content = Source{[FileName ="xl/workbook.xml"]}[Content],
ImportedXML = Xml.Tables(Content,null,TextEncoding.Utf8),
sheetsTable = ImportedXML{[Name = "sheets"]}[Table],
sheetTable = sheetsTable{[Name = "sheet"]}[Table],
ExpandedRel = Table.ExpandTableColumn(sheetTable, "http://schemas.openxmlformats.org/officeDocument/2006/relationships", {"Attribute:id"}, {"Attribute:id"}),
typed = Table.TransformColumnTypes(ExpandedRel,{{"Attribute:name", type text}, {"Attribute:sheetId", Int64.Type}, {"Attribute:id", type text}})
in
typed,
// sheets relations id to XML target files
workbook_rels =
let
Source = UnZipped,
Filtered = Table.SelectRows(Source, each [FileName]="xl/_rels/workbook.xml.rels"),
GetXML = Table.TransformColumns(Filtered, {"Content", each Xml.Tables(_,null,65001)}),
XMLContent = GetXML{0}[Content]{[Name="Relationship"]}[Table],
FilteredSheetsRel = Table.SelectRows(XMLContent, each [#"Attribute:Type"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"),
Removed = Table.RemoveColumns(FilteredSheetsRel,{"Attribute:Type"})
in
Removed,
// merge relations id (via sheets name)
MergedRelationsID = Table.Join(FilteredByNames, {"Name"}, workbook, {"Attribute:name"}),
// join workbook relations
MergedRelationsTarget = Table.Join(MergedRelationsID,{"Attribute:id"},workbook_rels,{"Attribute:Id"}),

@hohlick hohlick self-assigned this Aug 15, 2017
@hohlick hohlick added this to To Do in Cell Indents Aug 17, 2017
@hohlick hohlick moved this from To Do to Problems / Need Help in Cell Indents Aug 17, 2017
@hohlick hohlick moved this from Problems / Need Help to Further Note in Cell Indents Aug 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Cell Indents
Further Note
Development

No branches or pull requests

1 participant