Hi Ramna,
Hi,
Thanks for the reply. I’ve already been using 8.1.0.2 version. Anyhow i tried the dlls you attached but its of no use. I’m attaching a sample application based on my requirement. Please provide me solution.
Hi Ramna,
Hi Ramna,
//Set embedded ole object data.
sheetReport.OleObjects[0].ObjectData = objectData;
sheetReport.OleObjects[0].DisplayAsIcon = true;
// sheetReport.OleObjects[r].HasLine = false;
if (Path.GetExtension(path) == “.pdf”)
{
sheetReport.OleObjects[0].FileFormatType = FileFormatType.Pdf;
}
else if (Path.GetExtension(path) == “.docx”)
{
sheetReport.OleObjects[0].FileFormatType = FileFormatType.Docx;
}
else if (Path.GetExtension(path) == “.pptx”)
{
sheetReport.OleObjects[0].FileFormatType = FileFormatType.Pptx;
}
No, I need the three files to be embedded in an a single cell or a single row. What i have given to u guys is a sample where i hard coded it. If the ‘i’ in sheetReport.OleObjects[i].Objectdata represents the row number, then aspose.cells is able to embed only a single file in a row…This is as per my understanding…Please correct me if i’m wrong.
Hi Ramna,
yeah that helps, Could you please post the code for it.
Hi Ramna,
var wb = new Workbook();
var sheetReport = wb.Worksheets[0];
sheetReport.Name = “Report”;
Cells cells = sheetReport.Cells;
string imageUrl=string.Empty;
var paths = (ConfigurationManager.GetSection(“Paths”) as NameValueCollection);
for (int i = 0; i < paths.AllKeys.Count()-1;i++ )
{
string path = paths[i];
if (Path.GetExtension(path) == “.pdf”)
{
imageUrl =
Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
.Replace(@“bin\Debug”, “”), @“Images\pdficon.jpg”);
}
else if (Path.GetExtension(path) == “.docx”)
{
imageUrl =
Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
.Replace(@“bin\Debug”, “”), @“Images\wordicon.jpg”);
}
else if (Path.GetExtension(path) == “.pptx” || Path.GetExtension(path) == “.ppt”)
{
imageUrl =
Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
.Replace(@“bin\Debug”, “”), @“Images\ppticon.jpg”);
}
//Get the picture into the streams.
FileStream fs = File.OpenRead(imageUrl);
//Define a byte array.
byte[] imageData = new Byte[fs.Length];
//Obtain the picture into the array of bytes from streams.
fs.Read(imageData, 0, imageData.Length);
//Close the stream.
fs.Close();
fs = File.OpenRead(path);
//Define an array of bytes.
byte[] objectData = new Byte[fs.Length];
//Store the file from streams.
fs.Read(objectData, 0, objectData.Length);
//Close the stream.
fs.Close();
sheetReport.Cells.InsertColumn(0);
sheetReport.OleObjects.Add(0, 0, 25, 25, imageData);
//Set embedded ole object data.
sheetReport.OleObjects[i].ObjectData = objectData;
sheetReport.OleObjects[i].DisplayAsIcon = true;
// sheetReport.OleObjects[r].HasLine = false;
if (Path.GetExtension(path) == “.pdf”)
{
sheetReport.OleObjects[i].FileFormatType = FileFormatType.Pdf;
}
else if (Path.GetExtension(path) == “.docx”)
{
sheetReport.OleObjects[i].FileFormatType = FileFormatType.Docx;
}
else if (Path.GetExtension(path) == “.pptx”)
{
sheetReport.OleObjects[i].FileFormatType = FileFormatType.Pptx;
}
}
wb.Save(@“Sample.xlsx”, SaveFormat.Xlsx);
Hi Babar,
Thanks for the clarification. But the issue is that when i loop the code you mentioned for each row, it throws an an error at Save “Buffer cannot be null. Parameter name: buffer”. Can you provide code to loop it for each row.
Hi Ramna,
Hi Ramna,
Hi,
Thanks for using Aspose.Cells.
We have evaluated your issue further. Please change your code as the following:
C#
static void insertObjectsInOneRow(NameValueCollection paths, int row, int column)
{
for (int i = 0; i < paths.AllKeys.Count(); i++)
{
string path = paths[i];
string imageUrl = getFileType(path);
int index = sheet.OleObjects.Add(row, column++, 25, 25, getImageData(imageUrl));
//Set embedded ole object data.
sheet.OleObjects[index].ObjectData = getFileData(path);
sheet.OleObjects[index].DisplayAsIcon = true;
if (Path.GetExtension(path) == “.pdf”)
{
sheet.OleObjects[index].FileFormatType = FileFormatType.Pdf;
}
else if (Path.GetExtension(path) == “.docx”)
{
sheet.OleObjects[index].FileFormatType = FileFormatType.Docx;
}
else if (Path.GetExtension(path) == “.pptx”)
{
sheet.OleObjects[index].FileFormatType = FileFormatType.Pptx;
}
}
}