TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Prasad Bhagat
NA
516
236.6k
print all values in a single excell sheet?
May 17 2016 9:15 AM
Dear all,
i have a event handler that print val each time ,
but now i want to print all the values at a time
so please help me
public class Program
{
static ImpinjReader reader = new ImpinjReader();
public const string ReaderHostname = "xxx.xxx.xxx.xxx";
static void Main(string[] args)
{
try
{
// Connect to the reader.
// Change the ReaderHostname constant in SolutionConstants.cs
// to the IP address or hostname of your reader.
reader.Connect("xxx.xxx.xxx.xxx");
// Get the default settings
// We'll use these as a starting point
// and then modify the settings we're
// interested in.
Settings settings = reader.QueryDefaultSettings();
// Tell the reader to include the antenna number
// in all tag reports. Other fields can be added
// to the reports in the same way by setting the
// appropriate Report.IncludeXXXXXXX property.
settings.Report.IncludeAntennaPortNumber = true;
// Set the reader mode, search mode and session
settings.ReaderMode = ReaderMode.AutoSetDenseReader;
settings.SearchMode = SearchMode.DualTarget;
settings.Session = 2;
// Enable antenna #1. Disable all others.
settings.Antennas.DisableAll();
settings.Antennas.GetAntenna(1).IsEnabled = true;
// Set the Transmit Power and
// Receive Sensitivity to the maximum.
settings.Antennas.GetAntenna(1).MaxTxPower = true;
settings.Antennas.GetAntenna(1).MaxRxSensitivity = true;
// You can also set them to specific values like this...
//settings.Antennas.GetAntenna(1).TxPowerInDbm = 20;
//settings.Antennas.GetAntenna(1).RxSensitivityInDbm = -70;
// Apply the newly modified settings.
reader.ApplySettings(settings);
// Assign the TagsReported event handler.
// This specifies which method to call
// when tags reports are available.
reader.TagsReported += OnTagsReported;
// Start reading.
reader.Start();
// Wait for the user to press enter.
Console.WriteLine("Press enter to exit.");
Console.ReadLine();
// Stop reading.
reader.Stop();
// Disconnect from the reader.
reader.Disconnect();
}
catch (OctaneSdkException e)
{
// Handle Octane SDK errors.
Console.WriteLine("Octane SDK exception: {0}", e.Message);
}
catch (Exception e)
{
// Handle other .NET errors.
Console.WriteLine("Exception : {0}", e.Message);
}
}
public class DataClass
{
public string antennaPortNumber;
public string epc;
public string countBytes;
private string AntennaPortNumber { get { return antennaPortNumber; } set { value = antennaPortNumber; } }
private string Epc { get { return epc; } set { value = epc; } }
private string CountBytes { get { return countBytes; } set { value = countBytes; } }
}
static void OnTagsReported(ImpinjReader sender, TagReport report)
{
// This event handler is called asynchronously
// when tag reports are available.
// Loop through each tag in the report
// and print the data.
List<DataClass> dtcls = new List<DataClass>();
DataClass dt = null;
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
excel.Application.Workbooks.Add(true);
Workbook excelPrint = excel.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Worksheet excelSheePrint = (Worksheet)excelPrint.Worksheets[1];
foreach (Tag tag in report)
{
dt = new DataClass();
dt.antennaPortNumber = tag.AntennaPortNumber.ToString();
dt.epc = tag.Epc.ToString();
dt.countBytes = tag.Epc.CountBytes.ToString();
dtcls.Add(dt);
}
try
{
int maxCol = dtcls.Count;
int maxRow = dtcls.Count;
//Title
//Header
for (int i = 0; i < dtcls.Count; i++)
{
excel.Cells[1, 0 + 1] = "AntennaPortNumber";
excel.Cells[1, 1 + 1] = "Epc";
excel.Cells[1, 2 + 1] = "CountBytes";
for (int j = 0; j < dtcls.Count; j++)
{
excel.Cells[i + 2, j + 1] = dtcls[j].antennaPortNumber.ToString();
excel.Cells[i + 2, j + 2] = dtcls[j].epc.ToString();
excel.Cells[i + 2, j + 3] = dtcls[j].countBytes.ToString();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
string dtime = DateTime.Now.ToString().Replace('/', '_');
dtime = dtime.Replace(':', '_');
string filepath = @"D:\";
string filename = filepath + dtime + ".xlsx";
excelSheePrint.SaveAs(filename, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing, true, false, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing);
excel.Quit();
}
}
this was printing for every record as a one excell sheet .
but i want to print all the values into one excell sheet ..
so kindly help me any one ...
Reply
Answers (
1
)
Funtion's for ComboBox
How to use the VLOOKUP function using NPOI c# ?