|
 |
|
[c# WinApp] Export Excel อย่างไร กรณีที่ผมใส่ BindingNavigator |
|
 |
|
|
 |
 |
|
เราต้องรู้ก่อนว่าexcel มันเริ่มหน้าตั้งแต่ rows ไหน
ยกตัวอย่างงานในแล็บนะครับ

จะเห็นว่า มันเริ่ม แถวที่ 5 กับ แถวที่ 60(จริงๆแล้วต้องเขียนโค้ดให้มัน เพิ่มค่าใน วันที่/โลหะหนัก/ผู้ทดสอบ ด้วย)
แต่ละหน้า ต้องใส่ ข้อมูล 38 แถว
ถ้าเราจัดหน้ามันประมาณนี้
Code (C#)
private void Form1_Load(object sender, EventArgs e)
{
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
string myPath = @"C:\Copper_25611010 012851.Report";
excelApp.Workbooks.Open(myPath);
int ipg = 5;
int inPage = 1;//นับจำนวนแถวในหน้า
for (int idb = 0; idb < dataGridView1.RowCount - 1; idb++)
{
// Add data in excel
excelApp.Cells[ipg, 2] = dataGridView1[idb,2].Value;
ipg++;
inPage++;//นับให้ครบช 38 เฉยๆ
//เปลี่ยนหน้า
if (inPage >= 38)
{
inPage = 1; //เริ่มนับ 1 ใหม้
ipg += 16;// ข้ามไปหน้าใหม่
}
}
}
การเช็คหน้านั้นมัหลายวิธีครับ ผมแค่ ทำคร่าวๆให้ดู
แต่หลักการคือ
จำนวนแถวแต่ละหน้ามันเท่ากันอยู่แล้ว
ต้องรู้ว่าจะข้ามไปหน้าใหม่ยังไง
ถ้าลองเขียนขั้นตอนการทำงานของโค้ดดู จะเห็นชัดมากขึ้น ครับ
|
 |
 |
 |
 |
Date :
2019-03-10 03:30:11 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|