如何制作B列的上升数据并保留借方和信用的相关值?
早上好。
我正在研究Google表。我正在使用应用程序脚本。您可以在以下链接中找到我的文件。
- [https://docs.google.com/spreadsheets/d/1ce5sppfkftih0udsoddmxb_9cd-hfh5w_q3liois5o8/edit?usp = sharing]
我有一个名为“日记”的表格。
杂志 | ||||
---|---|---|---|---|
Année2022 | fournnisseur | |||
MOI | 3 | |||
日期 | comptedétbediteopérationsdébitCrédit06 | forture forture | 24,00 | 6 |
-MARS | GROOVE | 06 | 24,00 | |
-MARS | 512 | BANQUE | ° | |
n | ||||
12-MARS | 7 | 巴士民谣音乐会 | 135,00 | |
12-MARS | 53 | CAISSE | 135,00 | |
客户端n° | ||||
28-MARS | 6 | GROOVE | 24,00 | |
28-MARS | 512 | BANQUE | 24,00 | |
forture fournisseur n° | ||||
totauxà记者 | 183,00 | 183,00 |
我还有一张名为“ Grand Livre”的表格,我试图以上升的方式报告表“日记帐”的数据(B列)的数据(B列)。 但是,带有“ 7”的帐户的第9行不在最后,应该在最后。
débitCrédit06 | Mars | |||
---|---|---|---|---|
-Mars | 512 | 24 | ||
28-Mars | 512 | 24 | ||
12- | 53 | 135 | ||
12-MARS | 7 | 135 | ||
06-MARS | 6 | 24 24 | ||
24 28-MARS | 记者 | 624à | ||
183 | 183 | 183 |
function monGrandLivre() {
var journal = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('journal')
var data = journal.getDataRange().getDisplayValues().filter(r => (!isNaN(Date.parse(r[0]))))
data = data.sort(function (a, b) {
return b[1] - a[1];
});
var result = []
result.push(['', '', '', 'Débit', 'Crédit'])
data.forEach(function (donnees, ligne) {
result.push([donnees[0], donnees[1], '', donnees[3], donnees[4]])
if (ligne != (data.length - 1)) {
if (data[ligne + 1][1] != data[ligne][1]) {
result.push(['', '', '', '', ''])
result.push(['', '', '', '', ''])
}
}
})
var grandLivre = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('grand livre')
grandLivre.clearContents()
grandLivre.getRange(1, 1, result.length, result[0].length).setValues(result)
grandLivre.getRange(result.length + 1, 3).setValue('à reporter')
grandLivre.getRange(result.length + 1, 4).setFormula('=sum(D2:D' + result.length + ')')
grandLivre.getRange(result.length + 1, 5).setFormula('=sum(E2:E' + result.length + ')')
}
您能帮我吗?
先感谢您。
Good morning to the community.
I'm working on Google Sheets. I'm using Apps Script. You can find my file in the following link.
- [https://docs.google.com/spreadsheets/d/1ce5sppfkftIh0uDsODDmXb_9Cd-hfh5w_q3lIoIS5o8/edit?usp=sharing]
I have one sheet named "journal" where I have the data of my journal.
Journal | ||||
---|---|---|---|---|
Année | 2022 | |||
Mois | 3 | |||
Date | Compte | Détail des opérations | Débit | Crédit |
06-mars | 6 | Groover | 24,00 | |
06-mars | 512 | Banque | 24,00 | |
facture fournisseur n° | ||||
12-mars | 7 | Bus balladium concert | 135,00 | |
12-mars | 53 | Caisse | 135,00 | |
versement client n° | ||||
28-mars | 6 | Groover | 24,00 | |
28-mars | 512 | Banque | 24,00 | |
facture fournisseur n° | ||||
Totaux à reporter | 183,00 | 183,00 |
I have also one sheet named "grand livre" where I tried to report the data of the sheet "journal" and sort the data of the accounts (column B) in an ascendant way.
But, the line 9 with the account "7" is not at the end and should be at the end.
Débit | Crédit | |||
---|---|---|---|---|
06-mars | 512 | 24 | ||
28-mars | 512 | 24 | ||
12-mars | 53 | 135 | ||
12-mars | 7 | 135 | ||
06-mars | 6 | 24 | ||
28-mars | 6 | 24 | ||
à reporter | 183 | 183 |
function monGrandLivre() {
var journal = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('journal')
var data = journal.getDataRange().getDisplayValues().filter(r => (!isNaN(Date.parse(r[0]))))
data = data.sort(function (a, b) {
return b[1] - a[1];
});
var result = []
result.push(['', '', '', 'Débit', 'Crédit'])
data.forEach(function (donnees, ligne) {
result.push([donnees[0], donnees[1], '', donnees[3], donnees[4]])
if (ligne != (data.length - 1)) {
if (data[ligne + 1][1] != data[ligne][1]) {
result.push(['', '', '', '', ''])
result.push(['', '', '', '', ''])
}
}
})
var grandLivre = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('grand livre')
grandLivre.clearContents()
grandLivre.getRange(1, 1, result.length, result[0].length).setValues(result)
grandLivre.getRange(result.length + 1, 3).setValue('à reporter')
grandLivre.getRange(result.length + 1, 4).setFormula('=sum(D2:D' + result.length + ')')
grandLivre.getRange(result.length + 1, 5).setFormula('=sum(E2:E' + result.length + ')')
}
Can you help me?
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想按文本而不是按值对B进行分类,请按以下方式更改
If you want to sort column B by text and not by value, change as follows