How to store Import Settings of Open() function in a separate expressionI need to open CSV files with various settings.
One of the examples is below:
dt = Open(
filePath,
Import Settings(
End Of Line( CRLF, CR, LF ),
End Of Field( Comma, CSV( 0 ) ),
Strip Quotes( 1 ),
Use Apostrophe as Quotation Mark( 0 ),
Use Regional Settings( 0 ),
Scan Whole File( 1 ),
Treat empty columns as numeric( 0 ),
CompressNumericColumns( 0 ),
CompressCharacterColumns( 0 ),
CompressAllowListCheck( 0 ),
Labels( 1 ),
Column Names Start( 18 ),
Data Starts( 19 ),
Lines To Read( "All" ),
Year Rule( "20xx" )
)
);
I would like to store these settings that come inside Import Settings() construct as a separate expression and then use it when opening a file.
Something like this (but it doesn't work this way obviously):
settings1 = Expr(
Import Settings(
<MY import="" settings="" here="">
)
);
settings2 = Expr(
Import Settings(
<SOME other="" import="" settings="" here="">
)
);
if(condition, importSettings = settings1, importSettings = settings2)
dt = Open(
filePath,
Eval(importSettings)
);</SOME></MY>
ScriptingRe: How to store Import Settings of Open() function in a separate expressionOne option could be wrapping them like this:
Names Default To Here(1);
settings1 = Expr(
dt = Open(
filePath,
Import Settings(
End Of Line(CRLF, CR, LF),
End Of Field(Comma, CSV(0)),
Strip Quotes(1),
Use Apostrophe as Quotation Mark(0),
Use Regional Settings(0),
Scan Whole File(1),
Treat empty columns as numeric(0),
CompressNumericColumns(0),
CompressCharacterColumns(0),
CompressAllowListCheck(0),
Labels(1),
Column Names Start(1),
Data Starts(2),
Lines To Read("All"),
Year Rule("20xx")
)
)
);
settings2 = Expr(
dt = Open(
filePath,
Import Settings(
End Of Line(CRLF, CR, LF),
End Of Field(Comma, CSV(0)),
Strip Quotes(1),
Use Apostrophe as Quotation Mark(0),
Use Regional Settings(0),
Scan Whole File(1),
Treat empty columns as numeric(0),
CompressNumericColumns(0),
CompressCharacterColumns(0),
CompressAllowListCheck(0),
Labels(1),
Column Names Start(5),
Data Starts(6),
Lines To Read("All"),
Year Rule("20xx")
)
)
);
filePath = "somefilehere";
settings1;
settings2;