A voir également:
- Modifier dans un fichier excel
- Liste déroulante excel - Guide
- Fichier rar - Guide
- Formule excel - Guide
- Modifier extension fichier - Guide
- Fichier host - Guide
1 réponse
Pour être plus claire, voici mon code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
namespace Ecrire_dans_un_fichier_excel
{
public partial class Form1 : Form
{
Excel.Application xl = new Excel.Application();
int k ,j;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
k = 1; j = 0;
Excel.Workbook wb;
wb = xl.Workbooks.Open(@"C:\Users\user\Desktop\eSSAIS\Essai2\suivi6.xlsx");
Excel.Sheets xlsheets = wb.Sheets; //Get the sheets from workbook
Excel.Worksheet excelWorksheet = (Excel.Worksheet)xlsheets[1];
while(j!=1)
{
string cellule = "A" + k.ToString();
Excel.Range excelCellH = (Excel.Range)excelWorksheet.get_Range(cellule + ":" + cellule, Type.Missing);
if (excelCellH == null)
{
excelCellH.Value2="jasmina";
j=1;
}
else k++;
}
wb.Close(true, @"C:\Users\user\Desktop\eSSAIS\suivi6.xlsx");
System.Runtime.InteropServices.Marshal.ReleaseComObject(wb);
wb = null;
xl.Quit();
xl = null;
System.IO.File.Copy(@"C:\Users\user\Desktop\eSSAIS\suivi6.xlsx", @"C:\Users\user\Desktop\eSSAIS\Essai2\suivi6.xlsx",true);
System.IO.File.Delete(@"C:\Users\user\Desktop\eSSAIS\suivi6.xlsx");
}
}
}
J'ai essayé d'enregistrer une copie ailleurs , puis écraser sur le dossier courant après la libération de l'excel, en vain ! :/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
namespace Ecrire_dans_un_fichier_excel
{
public partial class Form1 : Form
{
Excel.Application xl = new Excel.Application();
int k ,j;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
k = 1; j = 0;
Excel.Workbook wb;
wb = xl.Workbooks.Open(@"C:\Users\user\Desktop\eSSAIS\Essai2\suivi6.xlsx");
Excel.Sheets xlsheets = wb.Sheets; //Get the sheets from workbook
Excel.Worksheet excelWorksheet = (Excel.Worksheet)xlsheets[1];
while(j!=1)
{
string cellule = "A" + k.ToString();
Excel.Range excelCellH = (Excel.Range)excelWorksheet.get_Range(cellule + ":" + cellule, Type.Missing);
if (excelCellH == null)
{
excelCellH.Value2="jasmina";
j=1;
}
else k++;
}
wb.Close(true, @"C:\Users\user\Desktop\eSSAIS\suivi6.xlsx");
System.Runtime.InteropServices.Marshal.ReleaseComObject(wb);
wb = null;
xl.Quit();
xl = null;
System.IO.File.Copy(@"C:\Users\user\Desktop\eSSAIS\suivi6.xlsx", @"C:\Users\user\Desktop\eSSAIS\Essai2\suivi6.xlsx",true);
System.IO.File.Delete(@"C:\Users\user\Desktop\eSSAIS\suivi6.xlsx");
}
}
}
J'ai essayé d'enregistrer une copie ailleurs , puis écraser sur le dossier courant après la libération de l'excel, en vain ! :/