| ♥ 0 | Saudações a todos! Alguém sabe de um método para gerar o digito de controle dos artigos em vários artigos sem ter que ir abrindo cada artigo um por um? Eu tenho vários artigos e queria obter o digito de controle em massa dos artigos, estive e a procurar algumas metodologias para fazer no Excel e de seguida fazer uma exportação, mas não consegui nenhum resultado eficaz. Marcado como spam |
| Resposta privada Do google "how to generate ean 13 check digit" EAN–13 Check Digit Calculator Sum all the digits in even positions and multiply by 3; Add all the the digits in odd positions (except for the last one which is check digit) to the number you've got; Divide that number by 10 and take the remainder; If the remainder is not 0, subtract it from 10. Job done! Gerado pelo chatgpt, para c# using System;
public class EAN13CheckDigit
{
public static int CalculateCheckDigit(string ean)
{
if (ean.Length != 12)
{
throw new ArgumentException("EAN must be 12 digits long");
}
int[] eanDigits = new int[12];
for (int i = 0; i < 12; i++)
{
if (!char.IsDigit(ean[i]))
{
throw new ArgumentException("EAN must contain only digits");
}
eanDigits[i] = ean[i] - '0'; // Convert character to integer
}
// Sum all the digits in odd positions (1st, 3rd, 5th, 7th, 9th, 11th)
int oddSum = 0;
for (int i = 0; i < 12; i += 2)
{
oddSum += eanDigits[i];
}
// Sum all the digits in even positions (2nd, 4th, 6th, 8th, 10th, 12th)
int evenSum = 0;
for (int i = 1; i < 12; i += 2)
{
evenSum += eanDigits[i];
}
// Multiply the result of even_sum by 3
int totalSum = oddSum + (evenSum * 3);
// Find the remainder when total_sum is divided by 10
int remainder = totalSum % 10;
// If remainder is 0, check digit is 0, otherwise subtract remainder from 10
int checkDigit = (remainder == 0) ? 0 : 10 - remainder;
return checkDigit;
}
public static void Main(string[] args)
{
string ean = "400638133393";
int checkDigit = CalculateCheckDigit(ean);
Console.WriteLine($"The check digit for EAN-13 code {ean} is {checkDigit}");
}
}
Marcado como spam | |
| Resposta privada Boas @alexandredias, obrigado pela sugestão, não era propriamente gerar um novo código de barras que eu queria, mas vou tentar implementar para ver o resultado. Desde já agradeço.
Marcado como spam Comentários Olá Domingos, aquele código gera o check-digit que procura
Para um conjunto de 12 digitos, de forma que possa obter o dígito que procura. | |
| Resposta privada Obrigado, não é propriamente o que eu queria, mas pode ajudar. @brunogomes
Marcado como spam | |
| Resposta privada https://kb.aspose.com/pt/barcode/net/generate-ean13-barcode-in-csharp/ Marcado como spam | |
| Resposta privada Obrigado, tomei nota. Podes partilhar comigo a maneira para gerar essa rotina? @brunogomes
Marcado como spam | |
| Resposta privada Boa Tarde, isso não é possível. Apenas consegue fazer uma rotina para gerar codigos novos completos. Marcado como spam |