i'm struggling on how i could handling converting this System.Byte[] array in my table coming from my Datagridview, see the column containing the images that only display Sytem.Byte[]
this is the code that im using but still it only display texts.
private void ToCsV(DataGridView DGV, string filename)
{
try
{
if (DGV.Rows.Count != 0)
{
int RowCount = DGV.Rows.Count;
int ColumnCount = DGV.Columns.Count;
Object[,] DataArray = new object[RowCount + 1, ColumnCount + 1];
//add rows
int r = 0;
for (int c = 0; c <= ColumnCount - 1; c++)
{
for (r = 0; r <= RowCount - 1; r++)
{
DataArray[r, c] = DGV.Rows[r].Cells[c].Value;
} //end row loop
} //end column loop
Document oDoc = new Document();
oDoc.Application.Visible = true;
//page orintation
oDoc.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
dynamic oRange = oDoc.Content.Application.Selection.Range;
string oTemp = "";
for (r = 0; r <= RowCount - 1; r++)
{
for (int c = 0; c <= ColumnCount - 1; c++)
{
oTemp = oTemp + DataArray[r, c] + "\t";
}
}
//table format
oRange.Text = oTemp;
object Separator = WdTableFieldSeparator.wdSeparateByTabs;
object ApplyBorders = true;
object AutoFit = true;
object AutoFitBehavior = WdAutoFitBehavior.wdAutoFitContent;
oRange.ConvertToTable(ref Separator, ref RowCount, ref ColumnCount,
Type.Missing, Type.Missing, ref ApplyBorders,
Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing,
Type.Missing, ref AutoFit, ref AutoFitBehavior, Type.Missing);
oRange.Select();
oDoc.Application.Selection.Tables[1].Select();
oDoc.Application.Selection.Tables[1].Rows.AllowBreakAcrossPages = 0;
oDoc.Application.Selection.Tables[1].Rows.Alignment = 0;
oDoc.Application.Selection.Tables[1].Rows[1].Select();
oDoc.Application.Selection.InsertRowsAbove(1);
oDoc.Application.Selection.Tables[1].Rows[1].Select();
//header row style
oDoc.Application.Selection.Tables[1].Rows[1].Range.Bold = 1;
oDoc.Application.Selection.Tables[1].Rows[1].Range.Font.Name = "Tahoma";
oDoc.Application.Selection.Tables[1].Rows[1].Range.Font.Size = 14;
//add header row manually
for (int c = 0; c <= ColumnCount - 1; c++)
{
oDoc.Application.Selection.Tables[1].Cell(1, c + 1).Range.Text = DGV.Columns[c].HeaderText;
}
//table style
oDoc.Application.Selection.Tables[1].set_Style("Grid Table 4 - Accent 5");
oDoc.Application.Selection.Tables[1].Rows[1].Select();
oDoc.Application.Selection.Cells.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
//header text
foreach (Section section in oDoc.Application.ActiveDocument.Sections)
{
Range headerRange = section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
headerRange.Fields.Add(headerRange, WdFieldType.wdFieldPage);
headerRange.Text = "your header text";
headerRange.Font.Size = 16;
headerRange.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
}
/* string fileName = @"C:\Users\JethroPaulo\Desktop\a314bf90a43cb49873d014b00bb3672b.jpg"; //the picture file to be inserted
Object oMissed = oDoc.Paragraphs[2].Range; //the position you want to insert
Object oLinkToFile = false; //default
Object oSaveWithDocument = true;//default
oDoc.InlineShapes.AddPicture(fileName, ref oLinkToFile, ref oSaveWithDocument, ref oMissed);
//Insert text
Object oMissing = System.Reflection.Missing.Value;
var oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);
oPara1.Range.Text = "First Text";
oPara1.Range.InsertParagraphAfter();
Image sparePicture = fetch;
Clipboard.SetDataObject(sparePicture);
var oPara2 = oDoc.Content.Paragraphs.Add(ref oMissing);
oPara2.Range.Paste();
oPara2.Range.InsertParagraphAfter();*/
//save the file
oDoc.SaveAs(filename);
//NASSIM LOUCHANI
}
}
catch (Exception ex)
{
DialogResult result = MessageBox.Show(ex.Message.ToString(), "Critical Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}