Import only specfic columns and rows from XLSX file

I have the file myfile.xlsx file that looks like the following:

I want to use Import to create a dataset that drops the first row (“File generated automatically by software”), contains the second row as headers, imports only the 4th to 7th rows, and only the 2nd and 3rd columns.

I need help with specifying the columns to be imported.

What I have now is

Import[
 "myfile.xlsx",
 {"XLSX", "Dataset", "Sheet1" ,
  2 ;; (*drops the first row*)},
 HeaderLines -> 1
 ]

which gives all columns and all rows except of the first. I then manipulate it to create a new variable that has only the rows and columns I need.

But I am looking for a way to achieve this only using Import.

Any help?

Besides, when I do

Import[
 "myfile.xlsx",
 {"XLSX", "Dataset", "Sheet1" ,
  {1, 1}}
 ]

I get

4133aaa.png

Why the double rows? Shouldn’t it import only the first row of the first column?

I don’t think skipping row 3 can be done during import. You did not provide the file so we make one

SeedRandom[123];
data = RandomReal[1, {10, 3}]

fileData = {{"File generated automatically by software", "", ""}, {"t", "current", "voltage"}}~Join~data
Export["data.xlsx", fileData]

dataset = 
  Import["data.xlsx", {"Dataset", 1, 1 ;; 7, 2 ;; 3}, 
    "SkipLines" -> 1,
     HeaderLines -> 1] // Rest

Thanks.

My question is about specyfying rows to be imported.

Can I import only row 2 (which will be used as a header) and rows 4 to 7?

Something like

Import["data.xlsx", {
  "Dataset",
  1,(*in sheet no. 1*)
  {2, 5 ;; 7},(*import row 2 and rows 4 to 7*)
  2 ;; 3}, (*import only 2nd and 3rd columns *)
 "SkipLines" -> 
  1, (*skip the message automatically generated by software*)
 HeaderLines -> 1 (*use current and voltage as headers*)
 ]

?

A Span cannot be combined with an Integer. You can explicitly enumerate the rows

Import["data.xlsx",
 {"Dataset", 1, {1, 2, 4, 5, 6}, 2 ;; 3},
 "SkipLines" -> 1,
 HeaderLines -> 1 ]

That solves the confusion.

You can convert a simple Span to a Range using Apply

Range @@ (4 ;; 7)
(* {4, 5, 6, 7}  *)

and use it to build the list. This might be useful if you have several disjoint Span

{1, 2, Sequence @@ Range @@ (4 ;; 7), Sequence @@ Range @@ (10 ;; 13)}
(* {1, 2, 4, 5, 6, 7, 10, 11, 12, 13} *)