I am currently using DocumentFormat.OpenXml.Spreadsheet to generate an excel file. I also added a web query to it.
I now want to authenticate the user. So on click of refresh in excel, I want to request for username and password and then authenticate it in API.
This is the code I currently have for generating excel with webquery.
ConnectionsPart connPart = workbook.WorkbookPart.AddNewPart\<ConnectionsPart\>();
connPart.Connections = new Connections();
var connection1 = new Connection()
{
Id = 1,
Name = "Connection1",
Type = 4, //Web Query
WebQueryProperties = new WebQueryProperties {
Url = "myurlfordatarefresh"
}
};
connPart.Connections.Append(connection1);
Sheet sheet = new Sheet() { Id = relationshipId, SheetId = sheetId, Name = "mysheet" };
QueryTablePart qt = sheetPart.AddNewPart\<QueryTablePart\>();
qt.QueryTable = new QueryTable() { Name = "Connection", ConnectionId = connection1.Id, RefreshOnLoad = true };
DefinedNames definedNames = new DefinedNames();
definedNames.Append(new DefinedName()
{
Name = "Connection",
Text = "mysheet!$A$2:$A$2"
});
This code above is adding a web query and on download of the excel file, I am able to refresh and get data from url and data in file is getting replaced by latest data.
Is there some other property or any way here that can help me achieve authentication (ask for username and password). Could someone please help me here.