While exporting the database as pdf in net core mvc, I can't get the images in my products table as pdf, the photo name comes up
My code is as below. I do this in the controller. I used the iText library.
//Building the Data rows.
for (int i = 0; i < products.Count; i++)
{
string[] product = (string[])products[i];
sb.Append("<tr>");
for (int j = 0; j < product.Length; j++)
{
//Append data.
sb.Append("<td style='border: 1px solid #ccc'>");
sb.Append(product[j]);
sb.Append("</td>");
}
sb.Append("</tr>");
}
//Table end.
sb.Append("</tr>");
Related
I'm trying to input the data in my list of list of strings as rows in a ASP table element. All the correct data is passed through, but the rows repeat themselves by 3 times. How do add to the table element only once?
List<List<string>> table = NorthwindAccess.GetProducts(ddl_Supplier.SelectedItem.Value);
for (int i = 0; i < table.Count(); ++i)
{
for (int k = 1; k < table[i].Count(); ++k)
{
row1 = new TableRow(); //create as many rows as in each column (name, quantity, stock)
for (int j = 0; j < table.Count(); ++j)
{
string cellData = table[j][k];
TableCell cells = new TableCell();
cells.Text = cellData;
row1.Cells.Add(cells);
}
ProductsTable.Rows.Add(row1);
}
}
What I want is to export datatable to a .csv file.
Here is what I tried but the time it takes is too long:
string strFilePath= #"C:\myCSVfile.csv";
--
public void CreateCSVFile(DataTable dtDataTablesList, string strFilePath)
{
// Create the CSV file to which grid data will be exported.
StreamWriter sw = new StreamWriter(strFilePath, false);
//First we will write the headers.
int iColCount = dtDataTablesList.Columns.Count;
for (int i = 0; i < iColCount; i++)
{
sw.Write(dtDataTablesList.Columns[i]);
if (i < iColCount - 1)
{
sw.Write(",");
}
}
sw.Write(sw.NewLine);
// Now write all the rows.
foreach (DataRow dr in dtDataTablesList.Rows)
{
for (int i = 0; i < iColCount; i++)
{
if (!Convert.IsDBNull(dr[i]))
{
sw.Write(dr[i].ToString());
}
if (i < iColCount - 1)
{
sw.Write(",");
}
}
sw.Write(sw.NewLine);
}
sw.Close();
}
Is there some any other way to do this faster?
Thank you in advance for any suggestions.
It is now faster and this is what I did:
I counted the number of processors
Create a thread for each
Divide the rows over the threads
Have each export to their own file
Combine the files at the end
Add a nice progress-display
I have data taken from a gridview to a datatable. Now i want to display all these data in a crystal report.I wish to display them using a loop. How do i do it?
This is the code
string sColValues= "";
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < dt.Columns.Count; j++)
{
Context.Response.Write(dt);
sColValues += dt.Rows[i][j].ToString() + " ";
Response.Write(sColValues + "</br>");
sColValues = "";
}
}
I am using PdfPTable to generate PDF's and following is my relevant code which loops through the data from db.
The problem here is if there are 10 or more columns the PDF design gets horrible. Is there any way in iTextSharp that Columns gets auto shifted in PDF by specifying Columns i require & rest columns are shifted on next page.
// Table Head
foreach (var q in tempColumnNames)
{
PdfPCell cell = new PdfPCell(new Phrase(q, fntTableFont));
table.AddCell(cell);
}
// Table Body
for (int i = 0; i < model.Count; i++)
{
for (int j = 0; j < model[i].Count(); j++)
{
PdfPCell cell = new PdfPCell(new Phrase(model[i][j].ToString(), fntTableFont));
table.AddCell(cell);
}
}
There's nothing automatic but you can use PdfPtable.WriteSelectedRows to write only the required sections.
I would like to loop through a table that I created using C# code and display data pulled from a Sharepoint list which was formatted in a table. This is the code I came up with:
protected override void RenderContents(HtmlTextWriter output)
{
try
{
SPSite thisSite = SPControl.GetContextSite(Context);
using (SPWeb topWeb = thisSite.OpenWeb("/"))
{
SPList newsList = topWeb.Lists["Headlines"];
SPQuery query = new SPQuery();
query.ExpandRecurrence = true;
query.Query = NewsListCamlQuery;
query.RowLimit = 2;
SPListItemCollection coll = newsList.GetItems(query);
output.Write("<table border='0' style='width: 100%;'><tbody>");
for (int i = 0; i < 2; i++)
{
output.Write("<tr>");
for (int j = 0; j < 3; j++)
{
output.Write("<td>");
foreach (SPListItem item in coll)
{
int newsID = int.Parse(item.ID.ToString());
output.Write("<hr/>");
output.Write("<table style='width: 100%; height: 143px;'><tbody>");
output.Write("<tr><td valign='top'><h4>");
output.Write(item["Title"].ToString());
output.Write("</h4></td></tr>");
output.Write("<tr><td valign='top'><h4 class='ms-rteElement-H4B'><span style='font-size: 8pt;'>");
output.Write(item["Sub_x0020_Heading"].ToString());
output.Write("</span></h4></td></tr>");
output.Write("<tr><td valign='top'><span style='font-size: 8pt;'>");
output.Write("<img class='image' src='");
//output.Write(item["Photo"].ToString());
output.Write("' Width='64px' Height='48px' Border='0' alt='' style='margin: 5px;'/>");
output.Write(item["Details"].ToString());
output.Write("</span></td></tr>");
output.Write("<tr><td valign='top'>");
output.Write("<a class='mt-linkMore' href='/Lists/Headlines/DispForm.aspx?ID=");
output.Write(newsID);
output.Write("' <span style='font-size: 6pt;'>Read More</span></a></td></tr>");
output.Write("</tbody></table>");
}
output.Write("</td>");
}
output.Write("</tr>");
}
output.Write("</tbody></table>");
}
}
catch (Exception exception)
{
output.Write("Error : " + exception.Message);
}
}
This code is currently re-writing the same record in each cell. I would like for it to display the six records that is being pulled from the Sharepoint list.
if you want to display two lines of 3 cells, you should not put the foreach.
On the inside of the second loop, you can make reference directly to the element of your list:
for (int i = 0; i < 2; i++)
{
output.Write("<tr>");
for (int j = 0; j < 3; j++)
{
output.Write("<td>");
int index;
if (i = 0)
index = j;
else
index = j + 3;
SPListItem item = coll[index];
int newsID = int.Parse(item.ID.ToString());
...