Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
im writing an app that creates an excel file. The contents of the excel will be parts of another excel that will be read in. i just need to for example, read the excel and copy everything from row 2 to 3, and paste it in the new excel.
I can generate and excel with no problem, but finding it difficult to read an excel.


any ideas?
Posted

// you have to download GemBox.Spreadsheet.dll
using GemBox.Spreadsheet;


ExcelFile ef = null;
ef.LoadXls(_filePath);
//for get text
string[] array = new string[ef.Worksheets.Count];
int i = 0;
foreach (ExcelWorksheet ws in ef.Worksheets)
{
array[i] = ws.Name;
i++;
}

string text = "";

for (int j = 0; j < i; j++)
{
ExcelWorksheet sheet = ef.Worksheets[array[j]];

foreach (ExcelRow er in sheet.Rows)
{
foreach (ExcelCell ec in er.Cells)
{
if (ec.Value != null)
text += ec.Value.ToString() + " ";

}
text += "\n";
}
text += "\n\n";
}
//for Get Rich Text
string text = "";

for (int j = 0; j < i; j++)
{
ExcelWorksheet sheet = ef.Worksheets[array[j]];

foreach (ExcelRow er in sheet.Rows)
{
foreach (ExcelCell ec in er.Cells)
{
if (ec.Value != null)
{
text += ec.Value.ToString() + "\n(";
text += ec.Style.Font.Name + "," + ec.Style.Font.Color.ToString() + ")\n";
}

}
text += "\n\n";
}
text += "\n\n\n";
}
 
Share this answer
 
ok, so i have taken a different approach by taking the data i need and putting it onto clipboard but i cant seem to put it in the row i want to. its starting from the last cell i used


<pre lang="midl">// Copy a string to the Windows clipboard.
string sData = &quot;1\tStart\tOpen\tTest1\tExecute\tIntertop\t25\tStopChecklist;
System.Windows.Forms.Clipboard.SetDataObject(sData);



workSheet_range.get_Range(&quot;A3:N15&quot;,Type.Missing);
str = Convert.ToString(r);

worksheet.Paste(workSheet_range,false);
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900