I'm currently building a web application that will give users the same information they see on a table on the current page, in Excel spreadsheet format. I found some previous code in another project that did the same thing.
Small question first: Does anyone know how the Column ss:Width works? It's not an exact match. Column ss:AutoFitWidth="0" ss:Width="114"
returns a column width of 21.00...
Where I'm having most of my trouble is, all of the data that is passed into the spreadsheet has leading and tailing whitespace; I have no idea how to remove it. I've tried .Trim()
when I make my .ToString()
query and I've been looking into other methods, but I haven't seemed to find it.
The following is a snippet of my worksheet code:
<Worksheet ss:Name="UserMgmt1">
<Table>
@*Name*@
<Column ss:AutoFitWidth="0" ss:Width="114" />
<Row>
<Cell ss:StyleID="s29">
<Data ss:Type="String">Name</Data>
</Cell>
</Row>
@foreach (tbl_Users query in ViewBag.contents )
{
<Row>
<Cell ss:StyleID="s31">
<ss:Data ss:Type="String" >
@(query.Name.ToString().Trim())
</ss:Data>
</Cell>
</Row>
}
</Table>
</Worksheet>
Forgot to add the ActionResult that implements this code:
public ActionResult _Excel(tblUsers model)
{
List<tbl_Users> inquiriesList = UserManageModel.GetResults(model);
ViewBag.contents = inquiriesList;
return View("_Excel");
}
And the call:
@using (Html.BeginForm("_Excel", "UserManage", FormMethod.Post))
{
<input type="submit" value="View Detailed List of Users in Excel" />
}
The result looks like this in Excel, with that much whitespace surrounding each string item:
Administrator