G
GiJeet
Hello, I have a winforms app with some values in the app.config file I
use to create a connection string to excel. Some of the values
require quotes around the values within the connection string.
Here is an example of the connection string:
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=Book1.xls;Extended Properties=""Excel 8.0;HDR=YES;""";
Note the quotes around the Extended Properties values.
I have the following String.Format code (which doesn’t work):
sConnStr = String.Format(
"Provider={0};Data Source={1};Extended
Properties={2};HDR={3};",
Provider, FilePath, ExtendedProperties, SheetHeader
);
Where Provider, FilePath, ExtendedProperties, SheetHeader are all vars
holding the values from the app.config. However there are no quotes
around the Extended Properties values.
I tried to escape it but it produces an error:
sConnStr = String.Format(
"Provider={0};Data Source={1};Extended
Properties=/”{2};HDR={3};/”",
Provider, FilePath, ExtendedProperties, SheetHeader
);
I even tried to put the quotes around the values in the app.config but
that threw an error also.
Here’s the app.config section.
<appSettings>
<add key="BSFileName" value="C:\_ExcelReports\BalanceSheet.xlsx"/>
<add key="BSProvider" value="Microsoft.ACE.OLEDB.12.0"/>
<add key="BSExtendedProperties" value="Excel 12.0 Xml"/>
<add key="BSHeader" value="NO"/>
<add key="BSSheetName" value="Sheet1"/>
<add key="BSCell_TotalAssets" value="B4"/>
</appSettings>
So, how to have quotes around values in a String.Format function?
Help is appreciated. You can even combine the ExtendedProperties &
SheetHeader into one variable. Thanks
G
use to create a connection string to excel. Some of the values
require quotes around the values within the connection string.
Here is an example of the connection string:
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=Book1.xls;Extended Properties=""Excel 8.0;HDR=YES;""";
Note the quotes around the Extended Properties values.
I have the following String.Format code (which doesn’t work):
sConnStr = String.Format(
"Provider={0};Data Source={1};Extended
Properties={2};HDR={3};",
Provider, FilePath, ExtendedProperties, SheetHeader
);
Where Provider, FilePath, ExtendedProperties, SheetHeader are all vars
holding the values from the app.config. However there are no quotes
around the Extended Properties values.
I tried to escape it but it produces an error:
sConnStr = String.Format(
"Provider={0};Data Source={1};Extended
Properties=/”{2};HDR={3};/”",
Provider, FilePath, ExtendedProperties, SheetHeader
);
I even tried to put the quotes around the values in the app.config but
that threw an error also.
Here’s the app.config section.
<appSettings>
<add key="BSFileName" value="C:\_ExcelReports\BalanceSheet.xlsx"/>
<add key="BSProvider" value="Microsoft.ACE.OLEDB.12.0"/>
<add key="BSExtendedProperties" value="Excel 12.0 Xml"/>
<add key="BSHeader" value="NO"/>
<add key="BSSheetName" value="Sheet1"/>
<add key="BSCell_TotalAssets" value="B4"/>
</appSettings>
So, how to have quotes around values in a String.Format function?
Help is appreciated. You can even combine the ExtendedProperties &
SheetHeader into one variable. Thanks
G