-2
I would like to start a code that reads a column in an excel spreadsheet that contains CNPJ numbers and compares with PDF file names in a folder.
Example: value in an excel cell verses PDF file name, if true, if false.
Could give me a light.
Read the spreadsheet I’ve done but don’t know how to go through the PDF files saved in the folder.
BELOW the code I read the files:
static void Main(string[] args)
{
string[] arquivos = Directory.GetFiles(@"C:\Projects\MOD01-EnvioDeE-mail\fila\");
Console.WriteLine("Arquivos:");
foreach (string arq in arquivos)
{
string newArq = arq;
Console.WriteLine(arq);
}
}
BELOW the code I read the spreadsheet.
using System;
using System.Collections.Generic;
using System.Linq;
using ClosedXML.Excel;
using System.Text;
using System.Threading.Tasks;
using System.IO; // A BIBLIOTECA DE ENTRADA E SAIDA DE ARQUIVOS
using iTextSharp; //E A BIBLIOTECA ITEXTSHARP E SUAS EXTENÇÕES
using iTextSharp.text; //ESTENSAO 1 (TEXT)
using iTextSharp.text.pdf;//ESTENSAO 2 (PDF)
namespace LerPlanilhaExcel
{
class Program
{
static void Main(string[] args)
{
IXLWorkbook wb = new XLWorkbook();
IXLWorksheet ws = wb.Worksheets.Add("Sheet");
wb.SaveAs(@"C:\Projects\LerPlanilhaExcel\LerPlanilhaExcel\excel\MeuExcel.xlsx");
var workbook = new XLWorkbook(@"C:\Projects\LerPlanilhaExcel\LerPlanilhaExcel\excel\MEI_ATIVO26072021.xlsx");
StreamWriter logCnpj = new StreamWriter(@"C:\Projects\LerPlanilhaExcel\LerPlanilhaExcel\log\logsCnpj.txt");
int contador = 0;
int cont = 1;
for (int i = 1; i <= 89; i++) //são 89 praças
{
var sheet = workbook.Worksheet(i);
var linha = 2;
while (true)
{
var email = sheet.Cell("O" + linha).Value.ToString();
var cnpj = sheet.Cell("C" + linha).Value.ToString();
if (contador == 5) break;
if (string.IsNullOrEmpty(cnpj) && (string.IsNullOrEmpty(email)))
{
ws.Cell(cont, 1).Value = "CAMPO VAZIO";
ws.Cell(cont, 2).Value = "CAMPO VAZIO";
wb.SaveAs(@"C:\Projects\LerPlanilhaExcel\LerPlanilhaExcel\excel\MeuExcel.xlsx");
contador++;
}
else
{
Console.WriteLine(sheet.ToString() + linha + ": " + cnpj + "---" + email);
logCnpj.Write(cnpj + "###" + email + "\r\n");
ws.Cell(cont, 1).Value = cnpj;
ws.Cell(cont, 2).Value = email;
wb.SaveAs(@"C:\Projects\LerPlanilhaExcel\LerPlanilhaExcel\excel\MeuExcel.xlsx");
}
if (cnpj == )
{
}
//System.Threading.Thread.Sleep(100);
linha++;
cont++;
}
contador = 0;
}
workbook.Dispose();
logCnpj.Close();
Console.WriteLine("END");
}
}
}
This answers your question? Search for files by extension
– Augusto Vasques