Giter Club home page Giter Club logo

power-query-excel-formats's Issues

This is common part for sheet relations

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"}),

Add parameters

  1. Parameters
  • exclude WSRel
  • add column number (R1C1) as parameter
  • add column letter (A1) as parameter
  1. With column parameter - make pre-selection of cells (dont sure if it will help performance).

Replace argument FullPath with FileContent

Hi Max,
I tried to use this function in one of my solutions. However, current version cannot be used for Scheduled Refresh as Power BI can't determine data source.

I changed function - replaced argument FullPath with FileContent.
So, in query it look like
FullPath = "C:\Temp\File.xlsx"
file = File.Contents(FullPath)
Source = fGetNumberFormats( file , "SheetName", 1, true)
... and so one...

Scheduled refresh works fine with such structure.

BR,
Ivan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.